标签:next include lib set efi i++ out lse else
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #define INF 99999999 using namespace std; int n,m,k,cnt; int len[500001],head[500001],jdg[500001],que[500001]; struct uio{ int to,next,wei; }edge[500001]; void get(int x,int y,int z) { edge[++cnt].next=head[x]; edge[cnt].to=y; edge[cnt].wei=z; head[x]=cnt; } int main() { cin>>n>>m>>k; memset(head,-1,sizeof(head)); memset(len,0x3f,sizeof(len)); for(int i=1;i<=m;i++) { int a,b,c; cin>>a>>b>>c; get(a,b,c); } len[k]=0; que[1]=k; jdg[k]=1; int s=0,f=1; while(s<f) { s++; int num=que[s]; jdg[num]=0; for(int i=head[num];i!=-1;i=edge[i].next) if(len[edge[i].to]>len[num]+edge[i].wei) { len[edge[i].to]=len[num]+edge[i].wei; if(jdg[edge[i].to]==0) { jdg[edge[i].to]=1; que[++f]=edge[i].to; } } } for(int i=1;i<=n;i++) { if(len[i]==0x3f3f3f3f) cout<<"No Ways!!!"<<" "; else cout<<len[i]<<" "; } cout<<endl; return 0; }
标签:next include lib set efi i++ out lse else
原文地址:https://www.cnblogs.com/water-radish/p/9280689.html