//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判断正环的更多相关文章

  1. Currency Exchange POJ - 1860 (spfa)

    题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...

  2. poj 1860 (Bellman_Ford判断正环)

    题意:给出n种货币,m中交换关系,给出两种货币汇率和手续费,求能不能通过货币间的兑换使财富增加. 用Bellman_Ford 求出是否有正环,如果有的话就可以无限水松弛,财富可以无限增加. #incl ...

  3. Currency Exchange POJ - 1860 (spfa判断正环)

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  4. poj1860 Currency Exchange(spfa判断正环)

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

  5. poj3621 SPFA判断正环+二分答案

    Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big c ...

  6. (最短路 SPFA)Currency Exchange -- poj -- 1860

    链接: http://poj.org/problem?id=1860 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2326 ...

  7. HDU 1317(Floyd判断连通性+spfa判断正环)

    XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. HDU 1317XYZZY spfa+判断正环+链式前向星(感觉不对,但能A)

    XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  9. Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

随机推荐

  1. windows下python3使用pip安装scrapy提示安装失败

    我的环境:     python3.6,     win10,      原因:不能成功安装twisted,因为twisted与高版本的python有兼容问题. 解决:1,先下载twisted二进制文 ...

  2. git中常混淆的操作

    1, git fetch 和 git pull 参考链接: https://stackoverflow.com/questions/292357/what-is-the-difference-betw ...

  3. linux中目录处理命令

    目录 mkdir cd pwd rmdir cp mv rm mkdir 解释 命令名称:mkdir 命令英文原意:make directories 命令所在路径:/bin/mkdir 执行权限:所有 ...

  4. 蓝眼睛与红眼睛(The blue-eyed islanders puzzle)

    澳大利亚的华裔数学神童陶哲轩曾在网上贴出来一个问题 The blue-eyed islanders puzzle 让大家思考,逗大家玩儿. 说一个岛上有100个人,其中有5个红眼睛,95个蓝眼睛.这个 ...

  5. Geographic coordinate systems 坐标系和 wkid

    Well-Known ID 与对应的坐标系  地理坐标系 Well-known ID Name Well-known text 3819 GCS_HD1909 GEOGCS["GCS_HD1 ...

  6. bootstrap-table.js扩展分页工具栏,增加跳转到xx页

    新项目,准备引用bootstrap-table这个控件来展示页面上的表格,无奈这款控件的分页工具栏没有跳转到xx页的功能,为了适应公司美工(只会出图的美工,却跟我要求这要求那)的蛋疼需求,硬着头皮改了 ...

  7. SQL语法学习记录——JOIN

    学习内容参考来源:www.runoob.com JOIN准备 --为了方便练习,在数据库中创建演示数据: create database TEST; use TEST ; ---------- go ...

  8. HTML5基础-新增标签+新增属性+布局案例

    html5中常用的结构标签 article 文章 header 头部 nav 导航 section 区域 aside 侧边栏 hgroup 区块的相关信息 figure 定义一组内容及标题 figca ...

  9. 简单java web制作思路

    经过俩天的摸索,和学姐的帮助下终于做出来一个简单地网页版的学生信息添加的系统.接下来说一下答题的思路: 首先我个人习惯先做网页界面,创建3个jsp文件分别是添加界面,成功界面,失败界面.这件看起来更加 ...

  10. 【新人赛】阿里云恶意程序检测 -- 实践记录10.20 - 数据预处理 / 训练数据分析 / TF-IDF模型调参

    Colab连接与数据预处理 Colab连接方法见上一篇博客 数据预处理: import pandas as pd import pickle import numpy as np # 训练数据和测试数 ...