Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大牛看看为何超时#include<iostream> using namespace std; int n,m,w,num; struct node{ int u,v,t; }eadge[3000]; int bellman_ford(int num){ int i,j,dis[501]; for(i=1;i<=n;i++) dis[i]=0x007fffff; dis[1]=0; bool flod; for(i=1;i<n;i++){ flod=0; for(j=0;j<num;j++) if(dis[eadge[j].v]>dis[eadge[j].u]+eadge[j].t) { dis[eadge[j].v]=dis[eadge[j].u]+eadge[j].t; flod=1; } if(flod==0) return 1; } for(j=0;j<num;j++) if(dis[eadge[j].v]>dis[eadge[j].u]+eadge[j].t) return 0; return 1; } int main() { int i,a,b,c,j; cin>>j; while(j--) { num=0; cin>>n>>m>>w; for(i=1;i<=m;i++) { scanf("%d%d%d",&a,&b,&c); eadge[num].u=a; eadge[num].v=b; eadge[num++].t=c; eadge[num].u=b; eadge[num].v=a; eadge[num++].t=c; } for(i=1;i<=w;i++) { cin>>a>>b>>c; eadge[num].u=a; eadge[num].v=b; eadge[num++].t=-c; } if(!bellman_ford(num)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator