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 |
用的是bellman-ford感觉没错啊,谁能告诉我为什么wa#include "iostream" #include "vector" #define MAXNUM 9999999 using namespace std; typedef struct edge { int s; int e; int cost; }edge; int main(void) { int f,n,m,w,s,e,t; int i,j; int d[500]; vector<edge> edges; vector<edge>::iterator iter; edge temp; freopen("in.txt","r",stdin); cin>>f; L1: while (f--!=0) { cin>>n>>m>>w; for (i=0;i<m;i++) { cin>>s>>e>>t; s--; e--; temp.s=s; temp.e=e; temp.cost=t; edges.push_back(temp); temp.s=e; temp.e=s; temp.cost=t; edges.push_back(temp); } for (i=0;i<w;i++) { cin>>s>>e>>t; s--; e--; temp.s=s; temp.e=e; temp.cost=-t; edges.push_back(temp); } for (i=0;i<500;i++) { d[i]=MAXNUM; } d[0]=0; for (i=1;i<n;i++) { for (iter=edges.begin();iter!=edges.end();iter++) { if (d[iter->s]>d[iter->e]+iter->cost) { d[iter->s]=d[iter->e]+iter->cost; } } } for (iter=edges.begin();iter!=edges.end();iter++) { if (d[iter->s]>d[iter->e]+iter->cost) { cout<<"YES\n"; goto L1; } } cout<<"NO\n"; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator