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 ...
随机推荐
- 用urllib2实现一个下载器的思路
下载器的构造 用urllib2实现下载器时从以下几个层面实现功能和灵活性: handler redirect, cookie, proxy 动作 timeout 构造请求 headers: ua, c ...
- js提交前弹出提示框
<form target="_blank" name="f1" method="post" action="sub2.php ...
- hibernate4.3.8与spring mvc结合遇到的问题
2703 [2015-01-21 16:47:42 ] - [ip=, ref=, ua=, sid=] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Er ...
- HDU--杭电--1253--胜利大逃亡--广搜
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 【转】Android开发中的SQLite事务处理,即beginTransaction()方法
使用SQLiteDatabase的beginTransaction()方法可以开启一个事务,程序执行到endTransaction() 方法时会检查事务的标志是否为成功,如果程序执行到endTrans ...
- ubuntu sublime安装及配置
安装sublime-text-2: sudo add-apt-repository ppa:webupd8team/sublime-text-2 sudo apt-get update sudo ap ...
- Percona Live 2016 PPT整理-zhaiwx_yinfeng
https://yq.aliyun.com/articles/54454?spm=5176.100239.bloglist.32.CllwIr
- Java 8 Features – The ULTIMATE Guide--reference
Now, it is time to gather all the major Java 8 features under one reference post for your reading pl ...
- [Android]如何创建一个View的分割线
如何创建一个View的分割线,如上图 我们见介绍三种可以创建看起来很不错的view的分割线,如在button之间添加分割线. 这个例子是将为LinearLayout内的三个Button间添加分割线. ...
- nginx url 重写 [转]
本文转自 http://www.jbxue.com/article/2187.html 本文介绍nginx URL重写的相关知识,包括301重定向的内容等,希望对大家有所帮助. nginx rewri ...