mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:31:59 +00:00
P1144 最短路计数
R53741486
This commit is contained in:
parent
e4e1bb0e30
commit
cdd5086345
41
Luogu/problem/P1144/P1144.cpp
Normal file
41
Luogu/problem/P1144/P1144.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int mod = 100003;
|
||||
|
||||
int n, m, x, y, depth[1000005], cnt[1000005];
|
||||
vector<int> g[1000005];
|
||||
bool vis[1000005];
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> x >> y;
|
||||
g[x].push_back(y);
|
||||
g[y].push_back(x);
|
||||
}
|
||||
queue<int> q;
|
||||
depth[1] = 0;
|
||||
cnt[1] = 1;
|
||||
q.push(1);
|
||||
vis[1] = true;
|
||||
while (!q.empty()) {
|
||||
int t = q.front();
|
||||
q.pop();
|
||||
for (int i : g[t]) {
|
||||
if (!vis[i]) {
|
||||
vis[i] = true;
|
||||
depth[i] = depth[t] + 1;
|
||||
q.push(i);
|
||||
}
|
||||
if (depth[i] == depth[t] + 1) {
|
||||
cnt[i] = (cnt[i] + cnt[t]) % mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cout << cnt[i] % mod << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user