当前位置:网站首页>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;
}
边栏推荐
- The programmer's girlfriend gave me a fatigue driving test
- Pycharm useful shortcut keys
- Why did kubernetes win? The changes in the container circle!
- On the application of cluster analysis in work
- Examples of topological sequences
- Dataloader source code_ DataLoader
- 2022-2028 global rotary transmission system industry research and trend analysis report
- 20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking
- Which is better, server rental or hosting services in the United States?
- Query points in MATLAB Delaunay triangulation
猜你喜欢

Software engineering best practices - project requirements analysis

What is SRM system and how to standardize the internal procurement process of the company

BeanUtils. Copyproperties() vs. mapstruct

Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)

2022-2028 global electric yacht industry research and trend analysis report

76页智慧物流园区综合解决方案2022(附下载)

The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

ABAQUS 2022 software installation package and installation tutorial

2022-2028 global mobile scanning radiology room industry survey and trend analysis report
随机推荐
Examples of topological sequences
Quick start of wechat applet -- project introduction
Shell multitasking to download video at the same time
Query points in MATLAB Delaunay triangulation
2022-06-30: what does the following golang code output? A:0; B:2; C: Running error. package main import “fmt“ func main()
Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
2022-2028 global herbal diet tea industry research and trend analysis report
Redis - cache penetration, cache breakdown, cache avalanche
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
Software supply chain security risk pointing North for enterprise digitalization and it executives
2022-2028 global public address fire alarm system industry research and trend analysis report
Kubernetes ---- pod configuration container start command
2022-2028 global carbon fiber room scraper system industry research and trend analysis report
Operation record of reinitialization instance of Dameng database
Dataloader source code_ DataLoader
Fh6908a negative pole turn off synchronous rectification analog low voltage drop diode control IC chip tsot23-6 ultra low power rectifier 1W power consumption < 100ua static replacement mp6908
How do it outsourcing resident personnel position their pain points?
2022-2028 global ethylene oxide scrubber industry research and trend analysis report
On the application of cluster analysis in work
1175. prime number arrangement / Sword finger offer II 104 Number of permutations