标签:target cond long sync ace owb name mes ref
https://www.acwing.com/problem/content/1136/
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define x first
#define y second
#define inf 0x3f3f3f3f
const int N = 1e5 + 7, M = 4e5 + 7, mod = 100003;
int n, m;
int h[N], e[M], ne[M], idx;
int dist[N], cnt[N];
int q[N];
void add(int a, int b) {
ne[idx] = h[a], e[idx] = b, h[a] = idx++;
}
int bfs() {
memset(dist, 0x3f, sizeof dist);
dist[1] = 0;
cnt[1] = 1;
int hh = 0, tt = 0;
q[0] = 1;
while (hh <= tt) {
int t = q[hh++];
for (int i = h[t]; ~i; i = ne[i]) {
int j = e[i];
if (dist[j] > dist[t] + 1) {
dist[j] = dist[t] + 1;
cnt[j] = cnt[t];
q[++tt] = j;
}
else if (dist[j] == dist[t] + 1) cnt[j] = (cnt[j] + cnt[t]) % mod;
}
}
}
int main() {
IO;
cin >> n >> m;
memset(h, -1, sizeof h);
while (m--) {
int a, b;
cin >> a >> b;
add(a, b), add(b, a);
}
bfs();
for (int i = 1; i <= n; ++i) cout << cnt[i] << "\n";
return 0;
}
标签:target cond long sync ace owb name mes ref
原文地址:https://www.cnblogs.com/phr2000/p/14396117.html