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

## 一次A过，留下代码做纪念~（bellman-ford）

Posted by sunyi740 at 2016-03-24 22:17:29 on Problem 3259
```#include<iostream>
#include<cstring>
using namespace std;
int dis[6000];
int mix=10005;
int n,m,w;
struct edge
{
int u;
int v;
int t;
};
edge a[6000];

void bellman()
{
memset(dis,mix,sizeof(dis));
dis[1]=0;
for(int i=1;i<n-1;i++)
for(int j=1;j<=2*m+w;j++)
{
if(dis[a[j].u]+a[j].t<dis[a[j].v])
dis[a[j].v]=dis[a[j].u]+a[j].t;
}
int flag=0;
for(int j=1;j<=2*m+w;j++)
{
if(dis[a[j].u]+a[j].t<dis[a[j].v])
{
flag=1;
break;
}
}
if(flag==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return;
}

int main()
{
int f;
cin>>f;
while(f--)
{
cin>>n>>m>>w;
int i;
for(i=1;i<=2*m-1;i=i+2)
{
cin>>a[i].u>>a[i].v>>a[i].t;
a[i+1].u=a[i].v;
a[i+1].v=a[i].u;
a[i+1].t=a[i].t;
}
for(i=2*m+1;i<=2*m+w;i++)
{
cin>>a[i].u>>a[i].v>>a[i].t;
a[i].t=-a[i].t;
}
bellman();
}
return 0;
}
```

Followed by: