POJ 3259 Wormholes (判负环)】的更多相关文章

 POJ 3259 Wormholes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   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…
<题目链接> 题目大意: John的农场里N块地,M条路连接两块地,W个虫洞,虫洞是一条单向路,会在你离开之前把你传送到目的地,就是当你过去的时候时间会倒退Ts.我们的任务是知道会不会在从某块地出发后又回来,看到了离开之前的自己.总的来说,就是看图中有没有负权环. 解题分析:判负环模板题,下面用的是spfa算法.判负环的依据为:如果在最短路的松弛操作中,存在进入队列次数大于n的点,则说明该图存在负环. #include <cstdio> #include <cstring&g…
//判断负环 dist初始化为正无穷 //正环 负无穷 #include<iostream> #include<cstring> #include<queue> #include<algorithm> using namespace std; , M = ; int dist[N]; int h[N], e[M], w[M], ne[M], idx; int n,m,z; void add(int a,int b,int c) { e[idx]=b; w[i…
题意:John的农场里n块地,m条路连接两块地,k个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts.我们的任务是知道会不会在从某块地出发后又回来,看到了离开之前的自己. 思路:虫洞连接的边是负权值的,如果途中存在一个负环的话,他可以沿着这个换一直走,时间肯定为负值. #include<string.h> #include<stdio.h> const int N=510; const int inf=0x3fffffff; int start,num,n,dis…
虫洞(wormhole) FJ 在农场上闲逛时,发现他的农场里有很多虫洞.虫洞是一条特殊的有向路径,当 FJ 从它的一头走到另一头后,他将被传送到过去的某个时刻.FJ 的每个农场包括 N(1<=N<=500)块按1..N 编号的草地.M(1<=M<=2500)条草地间的道路以及W(1<=W<=200) 个虫洞. FJ 一直以来就渴望进行时间旅行,于是他开始做如下的打算:从某块草地出发,穿 过一些道路以及一些虫洞,最终回到他出发的草地.这样,他说不定能碰见过去的自 己:)…
Wormholes Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   Java class name: Main [Submit] [Status] [Discuss] Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A w…
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个虫洞,连接两块地的路是双向的,而虫洞是单向的,去到虫洞之后时间会倒退T秒,如果能遇到离开之前的自己就输出YES,反之就是NO. 分析: 就是求一幅图中有没有负权环路, 可以bellman n-1次后再跑一次看看能不能更新, 能更新说明有环. 也可以spfa记录入队次数, 入队次数大于等于N说明有负权环路 #include<cstdio>…
A friend of yours, an inventor, has built a spaceship recently and wants to explore space with it. During his first voyages, he discovered that the universe is full of wormholes created by some alien race. These wormholes allow one to travel to place…
/** problem: http://poj.org/problem?id=3259 spfa判负环: 当有个点被松弛了n次,则这个点必定为负环中的一个点(n为点的个数) spfa双端队列优化: 维护队列使其dist小的点优先处理 **/ #include<stdio.h> #include<deque> #include<algorithm> using namespace std; class Graphics{ ; * + ; const static int…