当前位置:网站首页>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;
}
边栏推荐
- 2022-2028 global ICT test probe industry research and trend analysis report
- 76 page comprehensive solution 2022 for smart Logistics Park (download attached)
- Shell multitasking to download video at the same time
- Rust controls Dajiang programmable UAV Tello
- Combining online and offline, VR panorama is a good way to transform furniture online!
- C language array interception, C string by array interception method (c/s)
- Is it safe to open a stock account of Huatai Securities online?
- Redis - cache penetration, cache breakdown, cache avalanche
- Lombok
- File reading and writing for rust file system processing - rust Practice Guide
猜你喜欢

Makefile notes (Yiwen Institute makefile)

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

Implementation of OSD on Hisilicon platform (1)
![[untitled]](/img/96/7f26614bbdcce71006e38ee34ab216.jpg)
[untitled]

The programmer's girlfriend gave me a fatigue driving test

How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?

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

Introduction to ES6 promise, new features of ES7 and es8 async and await

Random ball size, random motion collision

The full technology stack, full scene and full role cloud native series training was launched to help enterprises build a hard core cloud native technology team
随机推荐
The difference between union and union all in MySQL
Shell multitasking to download video at the same time
高等数学建模
Red Hat将在Project Atomic上运用容器负载服务器
Makefile notes (Yiwen Institute makefile)
Analysis of 8253a register
How do it outsourcing resident personnel position their pain points?
Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical
Rust book materials - yazhijia Library
leetcode 474. Ones and Zeroes 一和零(中等)
76 page comprehensive solution 2022 for smart Logistics Park (download attached)
C language array interception, C string by array interception method (c/s)
Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
Ybtoj exchange game [tree chain splitting, line segment tree merging]
2022-2028 global single travel industry research and trend analysis report
New trend of embedded software development: Devops
Is it safe to buy funds on the compass?
6-1 exploit -ftp exploit
Examples of topological sequences
Five minutes to understand the exploratory test