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 ...
随机推荐
- 代理-cglib代理
jdk的动态代理只可以为接口去完成操作,而cglib它可以为没有实现接口的类去做代理,也可以为实现接口的类去做代理. IDB package com.bjpowernode.proxy; /** * ...
- 范式通俗理解:1NF、2NF、3NF和BNCF
https://blog.csdn.net/wyh7280/article/details/83350722 范式通俗理解:1NF.2NF.3NF和BNCF原创hongiii 最后发布于2018-10 ...
- 「Flink」Flink 1.9 WebUI运行作业界面分析
运行作业界面 在以下界面中,可以查看到作业的名称.作业的启动时间.作业总计运行时长.作业一共有多少个任务.当前正在运行多少个任务.以及作业的当前状态. 这里的程序:一共有17个任务,当前正在运行的是1 ...
- Blazor初体验之寻找存储client-side jwt token的方法
https://www.cnblogs.com/chen8854/p/securing-your-blazor-apps-authentication-with-clientside-blazor-u ...
- java循环语句 总结笔记
1.for 循环语句 语法:for(initialization;condition;iteration) public class A { public static void main(Strin ...
- 服务器控件Repeater
在使用aspx开发中,如果一个页面做纯数据展示,Repeater会比GridView更适合,因为它是轻量级的 下面是最基本的用法: aspx: <table> <asp:Repea ...
- ansible基本使用(一)
ansible是什么? ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量 ...
- C++\CLI使用.net委托,*Callback注意"this"
今天在使用c++\cli的时候遇到了点关于委托,callback使用的问题,简单记录一下 首先贴段简单的C#中使用System.Threading.Timer的代码. Timer GameTim ...
- 如何将文本放置在div的底部显示呢?
转自:将文本定位于div的底部的方法 摘要: 下文讲述将文本放于div的底部的两种方法,如下所示: 实现思路: 思路1:采用绝对定位的方式,将其放置于div的底部 思路2:使用Line-height ...
- 删除Win10菜单中的幽灵菜单(ms-resource:AppName/Text )
新建一个 .bat文件,输入以下内容 @echo off taskkill /f /im explorer.exe taskkill /f /im shellexperiencehost.exe ti ...