标签:cst middle == cstring std eof 了解 ios 银河
#include<queue> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 20010 #define maxn 999999 using namespace std; bool vist,vis[N]; int n,m,x,y,z,w,tot; int in[N],dis[N],head[N]; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1; ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f; } struct Edge { int to,from,dis,next; }edge[N]; int add(int x,int y,int z) { tot++; edge[tot].to=y; edge[tot].dis=z; edge[tot].next=head[x]; head[x]=tot; } void begin() { tot=vist=0; memset(in,0,sizeof(in)); memset(dis,0,sizeof(dis)); memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head)); } int spfa(int s) { queue<int>q; bool vis[N]; for(int i=1;i<=n;i++) vis[i]=false,dis[i]=maxn; q.push(s),vis[s]=true,dis[s]=0; while(!q.empty()) { int x=q.front();q.pop(); for(int i=head[x];i;i=edge[i].next) { int t=edge[i].to; if(dis[t]>dis[x]+edge[i].dis) { dis[t]=dis[x]+edge[i].dis; if(!vis[t]) { in[t]++; vis[t]=true; q.push(t); if(in[t]>n) return true; } } } vis[x]=false; } return false; } int main() { while(1) { n=read(),m=read(); begin(); if(n==0&&m==0) break; for(int i=1;i<=m;i++) { x=read(),y=read(),z=read(),w=read(); add(x,y,z),add(y,x,w); } vist=spfa(1); if(vist||dis[n]==maxn) printf("No such path\n"); else printf("%d\n",dis[n]); } return 0; }
标签:cst middle == cstring std eof 了解 ios 银河
原文地址:http://www.cnblogs.com/z360/p/7398028.html