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 ...
随机推荐
- ubuntu忘记密码
Do these two things just to make sure: mount -o remount,rw / This first part remounts the root parti ...
- convert 时间转换
格式:CONVERT(data_type,expression[,style])说明:此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,c ...
- 移动端转PC --> PC跳转移动端
<script type=”text/javascript”>try {var urlhash = window.location.hash;if (!urlhash.match(“fro ...
- codevs3008加工生产调度(Johnson算法)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- HTML5 类型数组TypeArray(一)
1.起源 TypedArray是一种通用的固定长度缓冲区类型,允许读取缓冲区中的二进制数据. 其在WEBGL规范中被引入用于解决Javascript处理二进制数据的问题. TypedArray已经被大 ...
- (转)Call to undefined function mb_convert_encoding()
需要先enable mbstring 扩展库 在 php.ini里将; extension=php_mbstring.dll 前面的 ; 去掉mb_convert_encoding 可以指定多种输入编 ...
- ASP.NET常用编程代码(一)
1.为按钮添加确认对话框 Button1.Attributes.Add("onclick","return confirm(’确认?’)");button.at ...
- Linux命令--用户用户组管理
新增用户组 : groupadd groupadd [-g GID] 组名 不加-g 则按照系统默认的gid创建组,跟用户一样,gid也是从500开始的 修改用户组信息 : groupmod grou ...
- 最全ASCLL码
结果 描述 实体编号 space ! exclamation mark ! " quotation mark " # number sign # $ dollar sign $ ...
- UICollectionView出现the behavior of the UICollectionViewFlowLayout is not defined because:
2015-01-28 21:55:17.790 Demo[636:9351] the behavior of the UICollectionViewFlowLayout is notdefined ...