#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> PII;
const int N=10e5+10, M = 2 * 10e5 +10, INF = 0x3f3f3f3f;
int h[N], e[M], w[M], nex[M], idx = 0;
int dist[N];
bool vis[N];
int cnt[N];
int n, m;
void add(int a,int b, int c)
{
e[idx] = b;
w[idx] = c;
nex[idx] = h[a];
h[a] = idx++;
}
void dijkstra()
{
for (int i=0;i<N;i++)
{
vis[i] = false;
dist[i] = INF;
}
dist[1] = 0;
priority_queue<PII, vector<PII>, greater<PII> > heap;
heap.push({0, 1});
while (heap.size())
{
int t = heap.top().second;
heap.pop();
if (vis[t]) continue;
vis[t] = 1;
for (int i=h[t]; i!=-1;i = nex[i])
{
int j = e[i];
if (dist[j] > dist[t]+w[i])
{
cnt[j] = cnt[t];
dist[j] = dist[t]+w[i];
heap.push({dist[j], j});
}
if (dist[j] == dist[t] + w[i])
{
cnt[j] += cnt[t];
}
}
}
}
int main()
{
for (int i=0;i<N;i++)
{
h[i] = -1;
}
int a, b;
cin >> n >> m;
for (int i=0;i<m;i++)
{
cin >> a >> b;
add(a, b, 1);
add(b, a, 1);
}
dijkstra();
for (int i=1;i<=n;i++)
{
cout << cnt[i] << endl;
}
return 0;
}
https://www.luogu.com.cn/problem/P1144
球调