# POJ 1860 *** Currency Exchange

<pre class="html" name="code">#pragma warning(disable:4996)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
#include<cstring>
#include<sstream>
#include<set>
#include<string>
#include<iterator>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

struct W {
int i, j;
double r, c;
}edge[260];

int main(void) {
int n, m, s, a, b;
double v, r1, r2, c1, c2;
//处理输入
cin >> n >> m >> s >> v;
for (int i = 0; i < m; ++i) {
cin >> a >> b >> r1 >> c1 >> r2 >> c2;
edge[i * 2].i = a;
edge[i * 2].j = b;
edge[i * 2].r = r1;
edge[i * 2].c = c1;
edge[i * 2 + 1].i = b;
edge[i * 2 + 1].j = a;
edge[i * 2 + 1].r = r2;
edge[i * 2 + 1].c = c2;
}
//建立权重数组
double *dis=new double[n];
memset(dis, 0, sizeof(double)*n);
dis[s - 1] = v;
//开始寻找最小路径
int uu, vv;
bool flag = 1;//判断是否还能再继续松弛
for (int i = 0; i < n&&flag; ++i){//进行n-1次松弛操作，得到最小路径
flag = 0;//如果这次松弛操作不能再继续松弛，那么得到最小路径
for (int j = 0; j < 2 * m; ++j) {
uu = edge[j].j - 1, vv = edge[j].i - 1;
if (dis[uu] < (dis[vv] - edge[j].c)*edge[j].r) {
dis[uu] = (dis[vv] - edge[j].c)*edge[j].r;
flag = 1;//这一次的松弛操作还可以松弛
}
}
}
if (flag)cout << "YES" << endl;//flag=1，说明即使做了n-1次松弛操作，路径还能继续松弛，说明还有正循环
else cout << "NO" << endl;
return 0;
}


01-24 1801

02-16 4886

08-07 1529

05-28 344

06-15 787

02-28 179

01-17 874

01-15 59

01-14 952

06-11 855