标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 22405 | Accepted: 8095 |
Description
Input
Output
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
Source
#include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=200+5; int n,m,S,tot; int MON[2][MAXN]; double RC[2][MAXN],d[MAXN],V; bool flag; bool Bellman() { for(int i=1;i<=n;i++) d[i]=0; d[S]=V; for(int i=1;i<n;i++) { bool tg=false; for(int j=1;j<=tot;j++) { int u=MON[0][j]; int v=MON[1][j]; if(d[v]<(d[u]-RC[1][j])*RC[0][j]) { d[v]=(d[u]-RC[1][j])*RC[0][j]; tg=true; } } if(!tg) return false; } for(int i=1;i<=tot;i++) { int u=MON[0][i]; int v=MON[1][i]; if(d[v]<(d[u]-RC[1][i])*RC[0][i]) return true; } return false; } int main() { //freopen("in.txt","r",stdin); while(scanf("%d %d %d %lf",&n,&m,&S,&V)!=EOF) { tot=1; memset(MON,0,sizeof(MON)); memset(RC,0,sizeof(RC)); for(int i=0;i<m;i++) { int a,b; double c,d,e,f; scanf("%d %d %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f); MON[0][tot]=a; MON[1][tot]=b; RC[0][tot]=c; RC[1][tot]=d; tot++; MON[0][tot]=b; MON[1][tot]=a; RC[0][tot]=e; RC[1][tot]=f; tot++; } if(Bellman()) printf("YES\n"); else printf("NO\n"); } return 0; }
POJ 1860 Currency Exchange (Bellman ford)
标签:
原文地址:http://www.cnblogs.com/clliff/p/4676844.html