( ̄▽ ̄)"

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std; const int eps=1e-7;
const int MAXN=110;
int N,M,S;
double V,Vcur[MAXN],R[MAXN][MAXN],C[MAXN][MAXN];
bool vis[MAXN];
int cntNode[MAXN]; bool SPFA()
{
queue<int> que;
int u,v; for(int i=1;i<=N;i++)
Vcur[i]=0,vis[i]=0,cntNode[i]=0;
Vcur[S]=V;vis[S]=1;cntNode[S]=1;
que.push(S); while(!que.empty())
{
u=que.front();que.pop();
vis[u]=0; for(v=1;v<=N;v++)
{
if((Vcur[u]-C[u][v])*R[u][v]>Vcur[v]+eps)
{
Vcur[v]=(Vcur[u]-C[u][v])*R[u][v];
if(!vis[v])
{
vis[v]=1;
++cntNode[v];
que.push(v);
if(cntNode[v]>N)
return true;
}
}
}
}
return false;
} int main()
{
scanf("%d%d%d%lf",&N,&M,&S,&V);
int a,b;
double r,c,rr,cc;
while(M--)
{
scanf("%d%d%lf%lf%lf%lf",&a,&b,&r,&c,&rr,&cc);
R[a][b]=r;C[a][b]=c;
R[b][a]=rr;C[b][a]=cc;
}
if(!SPFA()) printf("NO\n");
else printf("YES\n");
return 0;
}

POJ 1860 Currency Exchange(SPFA+邻接矩阵)的更多相关文章

  1. POJ 1860 Currency Exchange (SPFA松弛)

    题目链接:http://poj.org/problem?id=1860 题意是给你n种货币,下面m种交换的方式,拥有第s种货币V元.问你最后经过任意转换可不可能有升值.下面给你货币u和货币v,r1是u ...

  2. POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)

    POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...

  3. 最短路(Bellman_Ford) POJ 1860 Currency Exchange

    题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...

  4. POJ 1860 Currency Exchange 最短路+负环

    原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  5. POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告

    三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...

  6. POJ 1860——Currency Exchange——————【最短路、SPFA判正环】

    Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u S ...

  7. 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19881   Accepted: 711 ...

  8. (简单) POJ 1860 Currency Exchange,SPFA判圈。

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

  9. poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)

    链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...

  10. POJ 1860 Currency Exchange【SPFA判环】

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

随机推荐

  1. 【多重背包】HDU 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) ...

  2. Gpt转mbr

    1)Shift + F10 2)diskpart 3)list disk 4)select dist 0 5)clean 6)convert mbr [注]mbr常用于windows操作系统,而gpt ...

  3. orm2

    数据库连接 var orm = require("orm"); orm.connect("mysql://username:password@host/database& ...

  4. ibatis->mybatis升级过程

    最终目录结构 resources spring applicationContext.xml sqlmap mapper aaamapper.xml bbbmapper.xml mybatis-con ...

  5. CODE[VS]-寻找子串位置-字符串处理-天梯青铜

    题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述 ...

  6. 动作Action

    /** * DelayTime延迟 * @param d Duration 延迟时间 */ auto delayTime = DelayTime::create(); sprite->runAc ...

  7. Unity灯光详解

    Lights will bring personality and flavor to your game. You use lights to illuminate the scenes and o ...

  8. 3.使用secureCRT连接PC,LINUX,开发板

    1.设置secureCRT(可选项):http://www.linuxyw.com/linux/gongxiang/20130505/161.html 2.使用secureCRT远程登录linux 3 ...

  9. Swift原理

    背景与概览 Swift 最初是由 Rackspace 公司开发的高可用分布式对象存储服务,并于 2010 年贡献给 OpenStack 开源社区作为其最初的核心子项目之一,为其 Nova 子项目提供虚 ...

  10. Chrome开发者控制台的这些功能你都知道吗?

    Chrome内置了一些开发者工具,这些工具提供了很多的功能.今天,我们将会专注于JavaScript控制台. 在我编程的过程中,这个控制台为我提供了大量的帮助. 如果你正在电脑端阅读这篇文章,你可以在 ...