Currency Exchange POJ - 1860 spfa判断正环
//spfa 判断正环
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N=1e4;
const int INF=2e9;
int h[N],to[N],ne[N],idx;
double r[N],c[N];
int n, m,X;
double V;
void add(int u,int v,double r1,double c1)
{
to[idx]=v;
r[idx]=r1;
c[idx]=c1;
ne[idx]=h[u];
h[u]=idx++;
}
double dist[N];
int times[N];
bool vis[N];
bool spfa(int st)
{
memset(vis,,sizeof vis);
memset(times,,sizeof times);
for(int i=;i<=n;i++)
dist[i]=-INF;
queue<int>q;
q.push(st);
vis[st]=;
dist[st]=V;
while(q.size())
{
int u=q.front();
q.pop();
vis[u]=false;
for(int i=h[u];~i;i=ne[i])
{
int v=to[i];
if(dist[v]<(dist[u]-c[i])*r[i])
{
dist[v]=(dist[u]-c[i])*r[i];
if(!vis[v])
{
q.push(v);
vis[v]=;
if(++times[v]>n)
return true;
}
}
}
}
return false;
}
int main()
{
while(cin>>n>>m>>X>>V)
{
idx=;
memset(h,-,sizeof h);
for(int i=;i<=m;i++)
{
int u,v;
double r1,c1,r2,c2;
cin>>u>>v>>r1>>c1>>r2>>c2;
add(u,v,r1,c1);
add(v,u,r2,c2);
}
if(spfa(X))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
Currency Exchange POJ - 1860 spfa判断正环的更多相关文章
- Currency Exchange POJ - 1860 (spfa)
题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...
- poj 1860 (Bellman_Ford判断正环)
题意:给出n种货币,m中交换关系,给出两种货币汇率和手续费,求能不能通过货币间的兑换使财富增加. 用Bellman_Ford 求出是否有正环,如果有的话就可以无限水松弛,财富可以无限增加. #incl ...
- Currency Exchange POJ - 1860 (spfa判断正环)
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- poj1860 Currency Exchange(spfa判断正环)
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- poj3621 SPFA判断正环+二分答案
Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big c ...
- (最短路 SPFA)Currency Exchange -- poj -- 1860
链接: http://poj.org/problem?id=1860 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2326 ...
- HDU 1317(Floyd判断连通性+spfa判断正环)
XYZZY Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1317XYZZY spfa+判断正环+链式前向星(感觉不对,但能A)
XYZZY Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路
Description Several currency exchange points are working in our city. Let us suppose that each point ...
随机推荐
- 记网站部署中一个奇葩BUG
网页中引用的文件名不要带 adv 等 近日在写好一个网页后就把他部署到apache上测试,结果用chrome访问时有个背景图片总显示不出来,但是用firefox等却一切正常, 关键是我用windows ...
- Linux运维--15.OpenStack vm使用keepalived 实现负载均衡
外接mariadb集群 实现负载均衡 实验环境 10.0.1.27 galera1 10.0.1.6 galera2 10.0.1.23 galera3 10.0.1.17 harpoxy1 hapr ...
- springBoot2.x启动项目报java.sql.SQLNonTransientConnectionException
将项目从springBoot1.x升级到springBoot2.x,启动报错: java.sql.SQLNonTransientConnectionException: Cannot load con ...
- PMP--1.6 项目经理
本节都是理论的东西,可以在管理没有思路的或者管理陷入困境的时候当做提升或解决问题的思路来看. 一.项目经理 1. 项目经理.职能经理与运营经理的区别 (1)职能经理专注于对某个职能领域或业务部门的管理 ...
- C# 二进制 十进制 十六进制 之间的转换
; Console.WriteLine(a.ToString("X")); //10进制转16进制 Console.WriteLine(Convert.ToString(a, )) ...
- for循环嵌套练习题or99乘法表
//输出1-10之间的和 public static void whileTest(){ //定义变量用于存储不断变化的和 int sum = 0; //定义变量,用于记录不断变化的被加数 int x ...
- 基于tensorflow2.0和cifar100的VGG13网络训练
VGG是2014年ILSVRC图像分类竞赛的第二名,相比当年的冠军GoogleNet在可扩展性方面更胜一筹,此外,它也是从图像中提取特征的CNN首选算法,VGG的各种网络模型结构如下: 今天代码的原型 ...
- MySQL基础(5) | 存储过程
MySQL基础(5) | 存储过程 一.基础 结束符[重要] mysql的命令行执行每一条命令是以分号结尾的,也就是说识别是否为一条命令,是根据分号决定的. 然而存储过程中设计多条语句,很可能出现多个 ...
- 题解 Luogu P3370
讲讲这题的几种做法: 暴力匹配法 rt,暴力匹配,即把字符串存起来一位一位判相等 时间复杂度$ O(n^2·m) $ 再看看数据范围 \(n\le10^5,m\le10^3\) 当场爆炸.当然有暴力分 ...
- 《HTML&CSS design and build websites》学习笔记(1)
Chapter 1: Structure Chapter 2: Text <head>表示标题,默认显示在第一行. <title>表示抬头,显示在浏览器的标签页,还有窗口栏. ...