Currency Exchange
主要找正环:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#define MAXN 52000
using namespace std;
const int INF=-<<;
bool vis[MAXN];
int head[MAXN];
int next[MAXN];
int s;
double dis[MAXN];
struct node
{
int u,v;
double r,c;
}p[MAXN];
int e,n,m;
int cnt[MAXN];
double v;
void addnode(int u,int v,double r,double c)
{
p[e].u=u;
p[e].v=v;
p[e].r=r;
p[e].c=c;
next[e]=head[u];
head[u]=e++;
}
bool relax(int u,int v,double r,double c)
{
if(dis[v]<(dis[u]-c)*r)
{
dis[v]=(dis[u]-c)*r;
return true;
}
return false;
}
bool spfa(int rc)
{
memset(vis,false,sizeof(vis));
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++)
dis[i]=;
dis[rc]=v;
vis[rc]=true;
queue<int>q;
q.push(rc);
++cnt[rc];
while(!q.empty()){
int pre=q.front();
q.pop();
vis[pre]=false;
for(int i=head[pre];i+;i=next[i])
{
if(relax(pre,p[i].v,p[i].r,p[i].c)&&!vis[p[i].v]){
if((++cnt[p[i].v])>n) return false;
q.push(p[i].v);
vis[p[i].v]=true;
}
}
}
return true;
}
int main()
{
memset(head, -, sizeof(head));
memset(next, -, sizeof(next));
e=;
int a,b;
double r1,c1,r2,c2;
scanf("%d%d%d%lf",&n,&m,&s,&v);
for(int i=;i<m;i++){
scanf("%d%d%lf%lf%lf%lf",&a,&b,&r1,&c1,&r2,&c2);
addnode(a,b,r1,c1);
addnode(b,a,r2,c2);
}
if(!spfa(s)) printf("YES\n");
else printf("NO\n");
return ;
}
Currency Exchange的更多相关文章
- POJ1860 Currency Exchange(bellman-ford)
链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- Currency Exchange(Bellman-ford)
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21349 Accepted: 765 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- Currency Exchange 分类: POJ 2015-07-14 16:20 10人阅读 评论(0) 收藏
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22180 Accepted: 8015 De ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
- poj 1860 Currency Exchange :bellman-ford
点击打开链接 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16635 Accept ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- POJ 1860 Currency Exchange (bellman-ford判负环)
Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several c ...
随机推荐
- Python字符串连接的5种方法
总结了一下Python字符串连接的5种方法: 加号 第一种,有编程经验的人,估计都知道很多语言里面是用加号连接两个字符串,Python里面也是如此直接用 "+" 来连接两个字符串: ...
- Thrift初用小结
thrift --gen csharp search.thrift thrift --gen java search.thrift Thrift是facebook的一个技术核心框架,07年四月开放 ...
- 命令行修复MBR分区
命令行修复MBR 1.shift+F10打开命令行 2.输入:diskpart 3.输入:list disk 查看磁盘信息 4.选择你要操作的磁盘:select disk 0 5.输入:clean,清 ...
- Using SSL Certificates with HAProxy--reference
原文地址:http://serversforhackers.com/editions/2014/07/29/haproxy-ssl-termation-pass-through/ Overview I ...
- CSS 让标点符号不出现在行首
word-break:break-all; 这条语句的作用是让语句到达边界的时候自动换行,但是正是这个样式让标点符号跑到了行首. 语法: word-break : normal | break-all ...
- asp.net C# 导出EXCEL数据
if (dt == null) { return ""; } Microsoft.Office.Interop.Excel.Application xlApp = new Micr ...
- for update和for update nowait的区别和使用
首先,for update 和for update nowait 是对操作的数据行进行加锁,在事务提交前防止其他操作对数据的修改. for update 和for update nowait主要区别在 ...
- 直接拿来用的15个jQuery代码片段
1.预加载图片 1 2 3 4 5 6 7 8 9 10 11 12 (function($) { var cache = []; // Arguments are image paths r ...
- 手把手教你DIY一个春运迁徙图(一)
换了新工作,也确定了我未来数据可视化的发展方向.新年第一篇博客,又逢春运,这篇技术文章就来交给大家如何做一个酷炫的迁徙图(支持移动哦).(求star 代码点这里) 迁徙图的制作思路分为静态的元素和变换 ...
- 【COGS1672】难存的情缘
[题目描述] 一天机房的夜晚,无数人在MC里奋斗着... 大家都知道矿产对于MC来说是多么的重要,但由于矿越挖越少,勇士们不得不跑到更远的地方挖矿,但这样路途上就会花费相当大的时间,导致挖矿效率底下. ...