# poj 1860 最短路—Bellman-Ford算法

(100 – 0.39) * 29.75 = 2963.3975 B币。问s币的金额经过交换最终

``````#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define mp make_pair
#define x first
#define y second
const int INF=0x3f3f3f3f;
const int N=111;
typedef pair<int,int>pii;
struct edge
{
int u,v;
double c,m;
edge(int u,int v,double c,double m):u(u),v(v),c(c),m(m){}
};
vector<edge>e;
double d[N];
int n,m,S;
double V;
bool BF()
{
for(int i=1;i<=n;i++)d[i]=0;
d[S]=V;
for(int i=1;i<n;i++){
bool flag=0;
for(int j=0;j<e.size();j++){
int u=e[j].u,v=e[j].v;
double c=e[j].c,m=e[j].m;
if(d[v]<(d[u]-m)*c){
flag=1;
d[v]=(d[u]-m)*c;
}
}
if(!flag)return false;
}
for(int j=0;j<e.size();j++){
int u=e[j].u,v=e[j].v;
double c=e[j].c,m=e[j].m;
if(d[v]<(d[u]-m)*c){
return true;
}
}
return false;
}
int main()
{
scanf("%d%d%d%lf",&n,&m,&S,&V);
int a,b;
double c1,c2,m1,m2;
for(int i=0;i<m;i++){
scanf("%d%d%lf%lf%lf%lf",&a,&b,&c1,&m1,&c2,&m2);
e.push_back(edge(a,b,c1,m1));
e.push_back(edge(b,a,c2,m2));
}
if(BF())printf("YES\n");
else printf("NO\n");
return 0;
}``````
原文作者：Bellman - ford算法
原文地址: https://blog.csdn.net/hjt_fathomless/article/details/51824275
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。