当前位置:网站首页>Luogu p1144 shortest circuit count
Luogu p1144 shortest circuit count
2022-07-01 00:19:00 【Star_.】
Give a N vertices M Undirected graphs with edges , The vertex number is 1-N. Ask from the top 1 Start , There are several shortest paths to every other point .
Original link
spfa Combination with chained forward star , It's a template question
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=0x7fffffff;
const int N = 1e6+5;
const int mod=100003;
int n,m;
struct node{
int x;
int next;
}edge[N<<2];
int vis[N],ans[N],dis[N],head[N];
int cnt;
void add(int x,int y){
edge[++cnt].x=y;
edge[cnt].next=head[x];
head[x]=cnt;
edge[++cnt].x=x;
edge[cnt].next=head[y];
head[y]=cnt;
}
void SPFA(){
for(int i=1;i<=n;i++){
dis[i]=INF;
vis[i]=0;
}
vis[1]=1;
dis[1]=0;
ans[1]=1;
queue<int> q;
q.push(1);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i;i=edge[i].next){
int x = edge[i].x;
if(dis[x]>dis[u]+1){
dis[x]=dis[u]+1;
ans[x] = ans[u];
if(!vis[x]){
vis[x]=1;
q.push(x);
}
}
else if(dis[x]==dis[u]+1)
ans[x]=(ans[x]+ans[u])%mod;
}
}
}
int main()
{
ios::sync_with_stdio(false);
int x,y;
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>x>>y;
add(x,y);
}
SPFA();
for(int i=1;i<=n;i++){
cout<<ans[i]<<endl;
}
return 0;
}
边栏推荐
- Netease cloud sign in lottery? That year I could sign in for 365 days. No? Look.
- Mysql database query optimization
- Error when starting PHP: [pool www] cannot get uid for user '@php_ fpm_ [email protected]’
- What does it mean to open an account online? Is it safe to open an account online?
- 2022-2028 global rampant travel industry research and trend analysis report
- Never use redis expired monitoring to implement scheduled tasks!
- 20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
- New trend of embedded software development: Devops
- 2022-2028 global electric yacht industry research and trend analysis report
- ABAQUS 2022 software installation package and installation tutorial
猜你喜欢

2022-2028 global public address fire alarm system industry research and trend analysis report

Which is better, server rental or hosting services in the United States?

2022-2028 global 3D printing ASA consumables industry research and trend analysis report

Why should VR panoramic shooting join us? Leverage resources to achieve win-win results

Quick start of wechat applet -- project introduction

2022-2028 global mobile scanning radiology room industry survey and trend analysis report

女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!

ABAQUS 2022 latest edition - perfect realistic simulation solution

Maxpool2d explanation -- Application in arrays and images

The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?
随机推荐
MaxPool2d详解--在数组和图像中的应用
高等数学建模
MySQL index test
2022-2028 global encrypted external hard disk industry research and trend analysis report
"Experience" my understanding of user growth "new users"
VR panorama adds contrast function to make the display of differentiation effect more intuitive!
20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
HP notebook disable touchpad after mouse is inserted
DNS server setup, forwarding, master-slave configuration
CTF tool (1) -- archpr -- including installation / use process
2022-2028 global rotary transmission system industry research and trend analysis report
Examples of topological sequences
Repetition is the mother of skill
composer
2022-2028 global capsule shell industry research and trend analysis report
Excuse me, does Flink support synchronizing data to sqlserver
Error 2059 when Navicat connects to MySQL
Redis - understand the master-slave replication mechanism
2022-2028 global plant peptone industry research and trend analysis report