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 ...
随机推荐
- iphone匹配邮箱的正则表达式
NSString *str = [NSString stringWithString:@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-z ...
- Win8 移除右键菜单中的SkyDrive Pro选项
Step 1:进入注册表编辑器 Win + R键调出运行窗口,然后输入regedit,进入注册表编辑器. Step 2:删除下面的键值 HKEY_CLASSES_ROOT\AllFilesystemO ...
- [Javascript] Logging Pretty-Printing Tabular Data to the Console
Learn how to use console.table to render arrays and objects in a tabular format for easy scanning ov ...
- Java基础知识强化之IO流笔记13:递归之不死神兔问题(斐波那契数列)
1.这个问题是如下的: 有一对兔子,从出生后第3个月起,每个月都生一对兔子,小兔子长到第3个月又生一对兔子,加入兔子都不死,问第20个月兔子的对数? 分析:我们找规律 兔子对数第1个月: 1 ...
- html+css+js实现复选框全选与反选
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 【开源java游戏框架libgdx专题】-11-核心库-演员类
演员类,又称为Actor类,是libgdx开发中最基本的元素,可以被继承. 演员类,从OpenGL类的角度来理解,可以称为一个二维场景节点.它本身具有位置(postion).边界矩形(类似Retang ...
- struts2学生信息管理系统篇章③
package com.java1234.util; public class PageUtil { //传进来四个参数,tagetUtil是跳转链接的头部,totalNum是总个数,currentP ...
- public static <T> Map<String, T> json2map
/** * json string convert to map with javaBean */ public static <T> Map<String, T> json2 ...
- spring-data-mongodb查询结果返回指定字段
方法1 DBObject dbObject = new BasicDBObject(); dbObject.put("status", 1); DBObject field ...
- ASP.NET5 静态文件
静态文件,包括HTML文件,CSS文件,图像文件和JavaScript文件,它是一个应用里所包含的资源. 1. 提供静态文件 默认的,静态文件存储在你的webroot目录下面,webroot的路径定义 ...