标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 21349 | Accepted: 7653 |
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
1 #include<stdio.h> 2 struct edge 3 { 4 int u , v ; 5 double r , c ; 6 }e[300]; 7 int n , m , s ; 8 double cap ; 9 int cnt = 0 ; 10 double d[300] ; 11 12 bool Bellman_ford() 13 { 14 for (int i = 1 ; i <= n ; i++) 15 d[i] = 0 ; 16 d[s] = cap ; 17 bool flag ; 18 for (int i = 1 ; i <= n ; i++) { 19 flag = 1 ; 20 for (int j = 0 ; j < cnt ; j++) { 21 if (d[e[j].v] < ( d[e[j].u] - e[j].c ) * e[j].r ) { 22 flag = 0 ; 23 d[e[j].v] = ( d[e[j].u] - e[j].c ) * e[j].r ; 24 } 25 } 26 if (flag) 27 return false ; 28 } 29 30 return true ; 31 } 32 33 int main () 34 { 35 freopen ("a.txt" , "r" , stdin) ; 36 scanf ("%d%d%d%lf" , &n , &m , &s , &cap) ; 37 while (m--) { 38 scanf ("%d%d%lf%lf" , &e[cnt].u , &e[cnt].v , &e[cnt].r , &e[cnt].c) ; 39 cnt++; 40 e[cnt].u = e[cnt - 1].v , e[cnt].v = e[cnt - 1].u ; 41 scanf ("%lf%lf" , &e[cnt].r , &e[cnt].c) ; 42 cnt++; 43 } 44 /*for (int i = 0 ; i < cnt ; i++) 45 printf ("u = %d , v = %d , e[i].r = %.2f , e[i].c = %.2f\n" , e[i].u , e[i].v , e[i].r , e[i].c) ;*/ 46 if (Bellman_ford()) 47 puts ("YES") ; 48 else 49 puts ("NO") ; 50 51 return 0 ; 52 }
Currency Exchange(Bellman-ford)
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4307236.html