# Bellman_Ford poj 1860

/*
Sample Input

3 2 1 20.0
1 2 1.00 1.00 1.00 1.00
2 3 1.10 1.00 1.10 1.00
Sample Output

YES

*/

#include<cstdio>
#include<cstring>

#define MAXVN 120
#define MAXEN 2200
#define INF 100000000

using namespace std;

typedef struct{
int u, v;
double value, c;
}Edge;
Edge eg[MAXEN];
double dis[MAXVN];

int vn, en;

int Bellman_Ford(int st, double v){
for(int i = 1; i <= vn; i++){
dis[i] = 0;
}
//printf("eg1v:%d\v", eg[1].v);
dis[st] = v;
bool realxed = 0;
for(int i = 1; i <= vn - 1; i++){
for(int j = 1; j <= en; j++){

if(dis[eg[j].v] < (dis[eg[j].u] - eg[j].c)*eg[j].value){
dis[eg[j].v] = (dis[eg[j].u] - eg[j].c)*eg[j].value;
realxed = 1;
}
//printf("dfsf");
}
if(!realxed)  break;
}

for(int j = 1; j <= en; j++){
if(dis[eg[j].v] < (dis[eg[j].u] - eg[j].c)*eg[j].value) return 1;
}
return 0;
}

int main(){
int n, m, s,a, b;
double v, rab, cab,rba, cba;
while(scanf("%d%d%d%lf", &n, &m, &s, &v) != EOF){
vn = n;en = 2*m;
int count = 1;
//printf("n:%d m:%d s:%d v:%lf\n", n, m, s, v);
while(m--){
scanf("%d%d%lf%lf%lf%lf",&a, &b, &rab, &cab, &rba, &cba);
//printf("eg1v:%d\n", b);
eg[count].u = a;
eg[count].v = b;
eg[count].value = rab;
eg[count++].c = cab;
eg[count].u = b;
eg[count].v = a;
eg[count].value = rba;
eg[count++].c = cba;
}
if(Bellman_Ford(s,v) == 1) printf("YES\n");
else printf("NO\n");
}
}


#### poj1860 Currency Exchange floyd判断正环 （手动翻译）

2016-01-24 16:13:46

#### poj1860Currency Exchange（最短路）

2016-05-28 21:36:47

#### poj1860(spfa)

2015-08-20 14:48:21

#### POJ1860 货币兑换（单源最短路径）

2012-12-12 10:55:03

#### poj 1860 Currency Exchange （最短路）

2014-02-16 09:30:09

#### POJ 1860 Bellman_Ford

2015-01-25 18:42:06

#### poj 1860 Bellman_ford

2012-12-15 21:29:14

#### POJ 1860 bellman_ford算法

2012-03-14 13:55:26

#### POJ 1860 bellman_ford

2013-10-05 22:09:37

#### poj_1860

2015-02-02 15:54:32