#include <iostream>
#include <cstring>
#define eps 1e-8
#define M 100000
using namespace std;
struct vertex
{
double r;
double c;
int u;
int v;
}ver[10000];
int k,n;
double node[110],v;
bool BF(int s)
{
int i,j;
//cout<<n<<endl;
for(i = 0;i < n;i ++)
{
for(j = 0;j < k;j ++)
{
//cout<<node[ver[j].v]<< (node[ver[j].u] - ver[j].c) * ver[j].r<<endl;;
if(node[ver[j].v] < (node[ver[j].u] - ver[j].c) * ver[j].r)
{
node[ver[j].v] = (node[ver[j].u] - ver[j].c) * ver[j].r;
}
}
}
if(node[s] > v) return 1;
for(j = 0;j < k;j ++)
{
if(node[ver[j].v]+eps< (node[ver[j].u] - ver[j].c) * ver[j].r)
return 1;
}
return 0;
}
int main()
{
int m,s,i,j,l,r;
double rab,cab,rba,cba;
while(cin>>n>>m>>s>>v)
{
k = 0;
for(i = 0;i < m;i ++){
cin>>l>>r>>rab>>cab>>rba>>cba;
ver[k].u = l;ver[k].v = r;
ver[k].r = rab;ver[k].c = cab;
k++;
ver[k].u = r;ver[k].v = l;
ver[k].r = rba;ver[k].c = cba;
k++;
}
for(i = 0;i <= n;i ++)
node[i] = 0;
node[s] = v;
if(BF(s) == 1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
//for(i = 0;i <= n;i ++)cout<<node[i]<<endl;
}
return 0;
}
ZOJ Problem Set - 1544 Currency Exchange
最新推荐文章于 2022-02-25 19:38:17 发布