poj1860 bellford man判正环
来源:互联网 发布:联通是什么网络模式 编辑:程序博客网 时间:2024/04/29 23:35
bellford man判正环
共能连n-1条边,松弛n-1次后
若能继续松弛就是有正环
#include <iostream>#include <stdio.h>#include <algorithm>#include <queue>#include <cstring>#include <math.h>#include <map>#define FOR(i,j,k) for(int i=j;i<=k;i++)using namespace std;int n,m;int s; //持有第s种double v; //持有s的本金int tot;double d[110];//s到各点struct node{ int a; int b; double r; //rate double c; //手续费}nd[220];bool bellman(){ memset(d,0,sizeof(d)); d[s]=v; bool flag; for(int i=1;i<=n-1;i++){ flag=false; for(int j=1;j<=tot;j++){ if(d[nd[j].b]<(d[nd[j].a]-nd[j].c)*nd[j].r) { d[nd[j].b]=(d[nd[j].a]-nd[j].c)*nd[j].r; flag=true; } } if(!flag) break; } for(int i=1;i<=tot;i++) if(d[nd[i].b]<(d[nd[i].a]-nd[i].c)*nd[i].r) return true; return false;}int main(){ while(scanf("%d%d%d%lf",&n,&m,&s,&v)!=EOF) { tot=0; int a,b; double rab,cab,rba,cba; while(m--) { scanf("%d%d%lf%lf%lf%lf",&a,&b,&rab,&cab,&rba,&cba); tot++; nd[tot].a=a; nd[tot].b=b; nd[tot].r=rab; nd[tot].c=cab; tot++; nd[tot].a=b; nd[tot].b=a; nd[tot].r=rba; nd[tot].c=cba; } //cout<<tot<<endl; if(bellman()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
0 0
- poj1860 bellford man判正环
- poj1860
- poj1860
- poj1860
- poj1860
- poj1860
- poj1860
- poj1860
- poj1860
- POJ1860
- poj1860
- POJ1860
- poj1860
- POJ1860
- poj1860
- poj1860
- POJ1860
- 【POJ1860】Currency Exchange【spfa判正环】
- [Android]反编译apk + eclipse中调试smali
- (乱码问题大都是由于工具之间的编码格式不统一)Oracle字符集的查看查询和Oracle字符集的设置修改
- [黑马程序员]——Java调用C/C++
- ZOJ 3866 Cylinder Candy(对体积和表面积 积分)
- Form表单自动提交
- poj1860 bellford man判正环
- yii2basic下使用ueditor
- 百度云服务器 CentOS 图形界面支持
- linked类简单实现,和模板类放置问题
- 基于ucosii+x86pc的俄罗斯方块源码
- 数据挖掘十大经典算法个人总结
- 黑马程序员——Java基础语法
- 关联式容器
- SqlServer 数据库邮件