You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
typedef pair<int, int> PII;
|
|
|
|
|
const int N = 100010, M = 400010;
|
|
|
|
|
const int MOD = 100003;
|
|
|
|
|
|
|
|
|
|
int n, m;
|
|
|
|
|
int cnt[N];
|
|
|
|
|
int dis[N];
|
|
|
|
|
bool st[N];
|
|
|
|
|
int h[N], e[M], ne[M], idx;
|
|
|
|
|
void add(int a, int b) {
|
|
|
|
|
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dijkstra() {
|
|
|
|
|
memset(dis, 0x3f, sizeof dis);
|
|
|
|
|
dis[1] = 0;
|
|
|
|
|
cnt[1] = 1; // 出发点到自己的最短路径有1条,长度是0
|
|
|
|
|
|
|
|
|
|
// 小顶堆q
|
|
|
|
|
priority_queue<PII, vector<PII>, greater<PII>> q;
|
|
|
|
|
q.push({0, 1});
|
|
|
|
|
|
|
|
|
|
while (q.size()) {
|
|
|
|
|
auto t = q.top();
|
|
|
|
|
q.pop();
|
|
|
|
|
int u = t.second;
|
|
|
|
|
|
|
|
|
|
if (st[u]) continue;
|
|
|
|
|
st[u] = true;
|
|
|
|
|
|
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
|
|
|
int j = e[i];
|
|
|
|
|
if (dis[j] > dis[u] + 1) {
|
|
|
|
|
dis[j] = dis[u] + 1;
|
|
|
|
|
cnt[j] = cnt[u];
|
|
|
|
|
q.push({dis[j], j});
|
|
|
|
|
} else if (dis[j] == dis[u] + 1)
|
|
|
|
|
cnt[j] = (cnt[j] + cnt[u]) % MOD;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
scanf("%d %d", &n, &m);
|
|
|
|
|
memset(h, -1, sizeof h);
|
|
|
|
|
while (m--) {
|
|
|
|
|
int a, b;
|
|
|
|
|
scanf("%d %d", &a, &b);
|
|
|
|
|
add(a, b), add(b, a);
|
|
|
|
|
}
|
|
|
|
|
dijkstra();
|
|
|
|
|
for (int i = 1; i <= n; i++) printf("%d\n", cnt[i]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|