反思 :等于号啊等于号,判断要==(=.=);
#include<cstdio> #include<algorithm> #include<cstdlib> #include<iostream> #include<vector> #include<queue> #include<cstring> using namespace std; typedef long long LL; struct e { int from,to; }; typedef struct{ int i,di; }node; bool operator < (node a,node b){return a.di>b.di;} vector<int>G[1000000]; struct e edge[2000005]; int dis[1000000],num[1000000]; int en=-1; priority_queue<node>q; void addedge(int a ,int n) { G[a].push_back(n); } int main() { memset(dis,0x7f,sizeof(dis)); memset(num,0,sizeof(num)); memset(edge,0,sizeof(edge)); int n,m,a,b; cin>>n>>m; for(int i=1;i<=m;i++) { scanf("%d%d",&a,&b); edge[++en]=(struct e){a,b}; addedge(a,en); edge[++en]=(struct e){b,a}; addedge(b,en); } q.push((node){1,0}); dis[1]=0;num[1]=1; while(!q.empty()) { node x=q.top(); q.pop(); if(dis[x.i]!=x.di)continue; for(int j=0;j<G[x.i].size();j++) { if(dis[edge[G[x.i][j]].to]==x.di+1) num[edge[G[x.i][j]].to]=(num[edge[G[x.i][j]].to]+num[x.i])%100003; if(dis[edge[G[x.i][j]].to]>x.di+1) { dis[edge[G[x.i][j]].to]=x.di+1; num[edge[G[x.i][j]].to]=num[x.i]; q.push((node){edge[G[x.i][j]].to,x.di+1}); } } } for(int j=1;j<=n;j++) printf("%d\n",num[j]); return 0; }
时间: 2024-10-03 02:45:59