0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 06:48:52 +00:00

P1144 最短路计数

R53741486
This commit is contained in:
Baoshuo Ren 2021-07-21 00:38:07 +08:00 committed by Baoshuo Ren
parent e4e1bb0e30
commit cdd5086345
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View 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;
}