标签:
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 100 + 10;
struct Edge{
int v;double c, r;
Edge(int _v = 0,double _c = 0,double _r = 0):v(_v),c(_c),r(_r){}
};
vector<Edge> e[maxn];
void ini(int n ){
for(int i = 0 ; i <= n ; ++i){
e[i].clear();
}
}
void addedge(int u,int v,double c,double r){
e[u].push_back(Edge(v,c,r));
}
int cnt[maxn];double d[maxn];
bool spfa(int s,int n,double v){
for(int i = 0 ; i <= n ; ++i) d[i] = 0;
d[s] = v;
queue<int> q;q.push(s);
memset(cnt, 0 , sizeof(cnt));
cnt[s] = 1;
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = 0 ; i < e[u].size();++i){
int v = e[u][i].v;
if(d[v] < (d[u] - e[u][i].c) * e[u][i].r){
d[v] = (d[u] - e[u][i].c) * e[u][i].r;
q.push(v);
if(++cnt[v] > n) return true;
}
}
}
return d[s] > v;
}
int main(){
int n,m,s;
double v;
scanf("%d%d%d%lf",&n,&m,&s,&v);
for(int i = 0 ; i < m ; ++i){
int a,b;double Rab,Cab,Rba,Cba;
scanf("%d%d%lf%lf%lf%lf",&a,&b,&Rab,&Cab,&Rba,&Cba);
addedge(a,b,Cab,Rab);
addedge(b,a,Cba,Rba);
}
puts(spfa(s,n,v)?"YES":"NO");
return 0;
}
[2016-04-13][POJ][1860][Currency Exchange]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/9fa0b946a67f5facac71856b8dc3d973.html