https://www.luogu.org/problemnew/show/P1144

题解:SPFA

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=100003;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,u,v;
int cnt,flag,temp,sum;
bool  vis[N];
char str;
ll dist[N];
ll ans[N];
struct node{
    ll x,val;
    bool operator <(const node&S)const{
        return val>S.val;
    }
}x,tmp;
priority_queue<node>q;
vector<node>G[N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        x.x=v;
        x.val=1;
        G[u].push_back(x);
        x.x=u;
        G[v].push_back(x);
    }
    x.x=1;
    x.val=0;
    ans[1]=1;
    vis[1]=1;
    dist[1]=0;
    q.push(x);
    while(!q.empty()){
        x=q.top();
        q.pop();
        for(int i=0,j=G[x.x].size();i<j;i++){
            tmp=G[x.x][i];
            if(vis[tmp.x]==0){
                vis[tmp.x]=1;
                tmp.val=x.val+tmp.val;
                dist[tmp.x]=tmp.val;
                ans[tmp.x]=0;
                q.push(tmp);
            }
            if(dist[tmp.x]==dist[x.x]+1){
                ans[tmp.x]=(ans[tmp.x]+ans[x.x])%MOD;
            }

        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    //}

#ifdef DEBUG
	printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Hello world!" << endl;
    return 0;
}