题目链接:558 - Wormholes 题目大意:给出n和m,表示有n个点,然后给出m条边,然后判断给出的有向图中是否存在负环. 解题思路:利用Bellman Ford算法,若进行第n次松弛时,还能更新点的权值,则说明有负环的存在. #include <stdio.h> #include <string.h> #define min(a,b) (a)<(b)?(a):(b) const int N = 10005; const int INF = 0x3f3f3f3f; i…
链接: http://poj.org/problem?id=3259 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#problem/B Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25079   Accepted: 8946 Description While exploring his many farms, Farmer…
题目:http://poj.org/problem?id=3259 题意:主要就是构造图, 然后判断,是否存在负图,可以回到原点 /* 2 3 3 1 //N, M, W 1 2 2 1 3 4 2 3 1 3 1 3 //虫洞 3 2 1 //N, M, W 1 2 3 2 3 4 3 1 8 */ #include <iostream> #include <cstring> using namespace std; + + ) * + ; + ; int N, M, W; //…
题目链接:http://poj.org/problem?id=3259 题目就是问你能否回到原点而且时间还倒回去了.题目中有些路中有单向的虫洞能让时间回到过去 所以只要将虫洞这条边的权值赋为负然后再判断有没有负环就行了. #include <iostream> #include <cstring> using namespace std; const int inf = 10001; int f , n , m , w ,dis[1001] , counts; struct TnT…
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/.未经本作者同意不得转载. https://blog.csdn.net/kenden23/article/details/37737817 本题就是须要检查有没有负环存在于路径中,使用Bellman Ford算法能够检查是否有负环存在. 算法非常easy,就是在Bellman Ford后面添加一个循环推断就能够了. 题目故事非常奇怪,小心读题. #include <stdio.h> #include…
Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 36729   Accepted: 13444 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Eac…
题意:给出n个点,m条正权的边,w条负权的边,问是否存在负环 因为Bellman_ford最多松弛n-1次, 因为从起点1终点n最多经过n-2个点,即最多松弛n-1次,如果第n次松弛还能成功的话,则说明存在有负环 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include…
题目链接:http://poj.org/problem?id=3259 题意:n个农场,m条双向路径,w条单向路径(虫洞).单向虫洞路径是负值.农夫想知道自己能不能看到自己(X). 题解:其实刚开始没太读懂题意.然后其实如果他能看到自己,说明已经通过虫洞形成了一个负环.也就是通过spfa寻找负环(负权回路).这里的判断就是加一个cnt[]数组记录该点的入队次数,大于等于n说明已经形成负环. 代码: #include<iostream> #include<cstdio> #inclu…
传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. 思路:一开始以为一个地方只能用一次,感觉好像有点难,后来发现自己读错题了,其实只要判断给你的这幅图存不存在正环就可以了,用dis[]表示某种货币的数量,然后bellman判断正环就可以了.(题目里强调结尾一定要原来的货币,但其实这是废话,因为是以原来的货币为起点的,所以你换出去了一定换的回来),正…