题意:有n个顶点,m条边,然后有w个洞,过每个洞的时间为-ti,求是否会时光倒流

分析:就是求是否存在负圈,用Bellman-Floyd判定是否存在负圈即可,注意是无向图,所以路径是双向可达的

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
const int INF=<<;
struct edge{
int from,to,cost;
};
edge es[maxn];
int n,m,w;
int d[maxn]; bool find_negative_loop(){
memset(d,,sizeof(d));
for(int i=;i<n;i++){
for(int j=;j<m*+w;j++){
edge e=es[j];
if(d[e.to]>d[e.from]+e.cost){
d[e.to]=d[e.from]+e.cost; if(i==n-) return true;
}
//cout<<d[e.to]<<endl;
}
}
return false;
} int main()
{
int t;
cin>>t;
while(t--)
{
scanf("%d%d%d",&n,&m,&w);
for(int i=;i<m*;i+=)
{
int s,e,t;
scanf("%d%d%d",&s,&e,&t);
es[i].from=s,es[i].to=e,es[i].cost=t;
es[i+].from=e,es[i+].to=s,es[i+].cost=t;
}
for(int i=m*;i<w+m*;i++)
{
int s,e,t;
scanf("%d%d%d",&s,&e,&t);
es[i].from=s,es[i].to=e,es[i].cost=-t;
}
if(find_negative_loop()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

POJ3259负环判定的更多相关文章

  1. POJ-2175 Evacuation Plan 最小费用流、负环判定

    题意:给定一个最小费用流的模型,根据给定的数据判定是否为最优解,如果不为最优解则给出一个比给定更优的解即可.不需要得出最优解. 解法:由给定的数据能够得出一个残图,且这个图满足了最大流的性质,判定一个 ...

  2. ACM: POJ 3259 Wormholes - SPFA负环判定

     POJ 3259 Wormholes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   ...

  3. UVA 558 判定负环,spfa模板题

    1.UVA 558 Wormholes 2.总结:第一个spfa,好气的是用next[]数组判定Compilation error,改成nexte[]就过了..难道next还是特殊词吗 题意:科学家, ...

  4. POJ-3259 Wormholes---SPFA判断有无负环

    题目链接: https://vjudge.net/problem/POJ-3259 题目大意: 农夫约翰在探索他的许多农场,发现了一些惊人的虫洞.虫洞是很奇特的,因为它是一个单向通道,可让你进入虫洞的 ...

  5. POJ3259 :Wormholes(SPFA判负环)

    POJ3259 :Wormholes 时间限制:2000MS 内存限制:65536KByte 64位IO格式:%I64d & %I64u 描述 While exploring his many ...

  6. [poj3259]Wormholes(spfa判负环)

    题意:有向图判负环. 解题关键:spfa算法+hash判负圈. spfa判断负环:若一个点入队次数大于节点数,则存在负环.  两点间如果有最短路,那么每个结点最多经过一次,这条路不超过$n-1$条边. ...

  7. POJ3259 Wormholes 【spfa判负环】

    题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  8. poj3259(spfa判负环)

    题目连接:http://poj.org/problem?id=3259 题意:John的农场里N块地,M条路连接两块地,W个虫洞,虫洞是一条单向路,会在你离开之前把你传送到目的地,就是当你过去的时候时 ...

  9. POJ3259(Wormholes) 判断负环

    题意: 农夫john发现了一些虫洞,虫洞是一种在你到达虫洞之前把你送回目的地的一种方式,FJ的每个农场,由n块土地(编号为1-n),M 条路,和W个 虫洞组成,FJ想从一块土地开始,经过若干条路和虫洞 ...

随机推荐

  1. echarts学习总结(二):一个页面存在多个echarts图形,图形自适应窗口大小

    如上图所示一个页面有两个echarts图形:散点图和折线图,如果还写为: myChart.setOption(option); window.onresize = myChart.resize; 则只 ...

  2. Guess the Array

    Guess the Array time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. spring项目中的定时任务实现和问题解决

    之前我用JAVA中的Timer类实现了服务器的定时任务,具体详见之前的博文. 后来发现了一个更简单的实现方式,利用spring中的@Scheduled注解实现觉得简单的很多. 确实spring封装的特 ...

  4. 初学HTML5的一点理解

    刚接触了一点点用h5移动端的一点知识,用自己最浅薄的理解来看解决自适应屏幕尺寸问题和适应屏幕尺寸的布局问题.这里,为了解决自适应屏幕尺寸问题大概需要做的就是把HTML中的元素的尺寸尽可能的用百分比表示 ...

  5. mysql分页pagination

    http://www.phpjabbers.com/php--mysql-select-data-and-split-on-pages-php25.html returns 20 records so ...

  6. Struts2语法--Ognl

    OGNL: Object Graph Navigation Language index.jsp: <body> 访问属性 <a href="<%=contextPa ...

  7. Codeforces Round #272 (Div. 1) B 构造 math

    http://www.codeforces.com/contest/477/problem/C 题目大意:给你n个集合,每个集合里面有四个数字,他们的gcd是k,输出符合条件的集合中m,m为集合中最大 ...

  8. Combox下拉绑定DataGridView

    这个Combox下拉很多人都在用  但其中绘制的语句如下: #endregion #region 方法 #region 绘制DataGridView以及下拉DataGridView private v ...

  9. Codeforces Round #367 (Div. 2)D. Vasiliy's Multiset (字典树)

    D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  10. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing

    B. Bear and Compressing 题目链接  Problem - B - Codeforces   Limak is a little polar bear. Polar bears h ...