POJ 1860 Currency Exchange Bellman判断正环

来源:互联网 发布:php session用法 编辑:程序博客网 时间:2024/06/05 07:30
这几天做最短路反正挺蒙b的~~~~~~
#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>using namespace std;struct node{    int u, v;    double w, r;}p[10000],t;int n, m, s;double v;double dis[2100];int g;int Bellman(){    int i, j;    for(i = 1;i <= n;i++) dis[i] = 0;    dis[s] = v;    for(i = 1;i <= n;i++){        for(j = 0;j < g;j++){            t = p[j];            if(dis[t.v] < (dis[t.u] - t.r)*t.w){                dis[t.v] = (dis[t.u] - t.r)*t.w;                if(i == n) return 1;            }        }    }    return 0;}int main(){    while(cin >> n >> m >> s >> v){        int a, b;        double c, d, e, f;        g = 0;        while(m--){            scanf("%d %d %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f);            p[g].u = a;            p[g].v = b;            p[g].w = c;            p[g].r = d;            g++;            p[g].u = b;            p[g].v = a;            p[g].w = e;            p[g].r = f;            g++;        }        if(Bellman()){            printf("YES\n");        }else {            printf("NO\n");        }    }    return 0;}

0 0