题目链接:https://www.luogu.org/problemnew/show/P1144
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int mod = ;
const int maxn = ;
const int inf = 0x7fffffff;
int n, m, dis[maxn], ans[maxn];
bool vis[maxn];
queue<int>q;
vector<int>e[maxn];
int SPFA()
{
while(!q.empty())
{
int now1 = q.front();
q.pop();
for(int i = ; i < e[now1].size(); i++)
{
int now2 = e[now1][i];
if(!vis[now2])
{
vis[now2] = ;
dis[now2] = dis[now1]+;
q.push(now2);
}
if(dis[now2] == dis[now1]+)
{
ans[now2] = (ans[now2] + ans[now1])%mod;
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i = ; i <= m; i++)
{
int u,v;
scanf("%d%d",&u,&v);
e[u].push_back(v);
e[v].push_back(u);
}
int s = ;
dis[s] = ;
q.push(s);
vis[s] = ;
ans[s] = ;
SPFA();
for(int i = ; i <= n; i++)
printf("%d\n",ans[i]);
}