Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 用的是bellman-ford感觉没错啊，谁能告诉我为什么wa

Posted by batmancn at 2010-09-09 21:34:35 on Problem 3259
```#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: