#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
#define X first
#define Y second
#define pid pair<int,double>
const int N=150;
vector<pid>e[N];
vector<pid>g[N];
int vis[N];
double quan[N];
int n,m,x;
double s;
void spfa(int root)
{
memset(vis,false,sizeof false);
memset(quan,0.0,sizeof quan);
quan[root]=s;
vis[root]=true;
queue<int>q;
q.push(root);
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=false;
for(int i=0; i<e[u].size(); i++)
{
int v=e[u][i].X;
double w=e[u][i].Y,k=g[u][i].Y;
double z=(quan[u]-k)*w;
if(z>quan[v]){
quan[v]=z;
if(!vis[v]){
vis[v]=true;
q.push(v);
}
if(v==root&&quan[v]>s){
printf("YES\n");
return ;
}
}
}
}
printf("NO\n");
return ;
}
int main()
{
scanf("%d%d%d%lf",&n,&m,&x,&s);
for(int i=0; i<n; i++)
{
e[i].clear();
g[i].clear();
}
while(m--)
{
int a,b;
double a1,b1,a2,b2;
scanf("%d%d%lf%lf%lf%lf",&a,&b,&a1,&a2,&b1,&b2);
if(a!=b)
{
e[a].push_back(pid(b,a1));
e[b].push_back(pid(a,b1));
g[a].push_back(pid(b,a2));
g[b].push_back(pid(a,b2));
}
}
spfa(x);
return 0;
}
【POJ1860】Currency Exchange【spfa判正环】
最新推荐文章于 2020-09-17 19:31:04 发布