1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
P1144 最短路计数.cpp 1.46 KB
Copy Edit Raw Blame History
charlie authored 2024-01-09 00:01 . move from github to gitee
#include <iostream>
#include <queue>
#include <vector>
#include <string.h>
#define mod 100003
using namespace std;
struct edge{
int stop,next;
};
int main(){
int n,m;
cin>>n>>m;
int ehead[n];
memset(ehead,-1,sizeof(ehead));
edge e[m*2];
bool vis[n];
int len[n];
int ans[n];
memset(vis,false,sizeof(vis));
memset(ans,0,sizeof(ans));
vis[0] = true;
len[0] = 0;
ans[0] = 1;
queue<int> q;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;
b--;
e[i*2].stop = b;
e[i*2].next = ehead[a];
ehead[a] = i*2;
e[i*2+1].stop = a;
e[i*2+1].next = ehead[b];
ehead[b] = i*2+1;
// cin>>a[i].x>>a[i].y;
// a[i].x--;
// a[i].y--;
}
q.push(0);
while(!q.empty()){
int start=q.front();
q.pop();
int index=ehead[start];
while(index != -1){
if(vis[e[index].stop] == true){
index = e[index].next;
continue;
}
if(ans[e[index].stop] == 0){
len[e[index].stop] = len[start]+1;
ans[e[index].stop] += ans[start];
ans[e[index].stop] %= mod;
q.push(e[index].stop);
index = e[index].next;
continue;
}
if(len[e[index].stop] < len[start]+1){
vis[e[index].stop] = true;
index = e[index].next;
continue;
}
if(len[e[index].stop] == len[start]+1){
ans[e[index].stop] += ans[start];
ans[e[index].stop] %= mod;
index = e[index].next;
continue;
}
}
}
for(int i=0;i<n;i++)
cout<<ans[i]%mod<<endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

Search

0d507c66 1850385 C8b1a773 1850385