POJ 3259——Wormholes——————【最短路、SPFA、判负环】
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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! Each of FJ's farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..N, M (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.
As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .
To help FJ find out whether this is possible or not, he will supply you with complete maps to F (1 ≤ F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.
Input
Line 1 of each farm: Three space-separated integers respectively: N, M, and W
Lines 2.. M+1 of each farm: Three space-separated numbers ( S, E, T) that describe, respectively: a bidirectional path between S and E that requires T seconds to traverse. Two fields might be connected by more than one path.
Lines M+2.. M+ W+1 of each farm: Three space-separated numbers ( S, E, T) that describe, respectively: A one way path from S to E that also moves the traveler back T seconds.
Output
Sample Input
2
3 3 1
1 2 2
1 3 4
2 3 1
3 1 3
3 2 1
1 2 3
2 3 4
3 1 8
Sample Output
NO
YES
Hint
For farm 2, FJ could travel back in time by the cycle 1->2->3->1, arriving back at his starting location 1 second before he leaves. He could start from anywhere on the cycle to accomplish this.
POJ 3259——Wormholes——————【最短路、SPFA、判负环】的更多相关文章
- 解题报告:poj 3259 Wormholes(入门spfa判断负环)
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...
- POJ 3259 Wormholes(最短路径,求负环)
POJ 3259 Wormholes(最短路径,求负环) Description While exploring his many farms, Farmer John has discovered ...
- POJ——1364King(差分约束SPFA判负环+前向星)
King Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11946 Accepted: 4365 Description ...
- bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞【spfa判负环】
tag是假的,用了及其诡异的方法判负环 正权无向边和负权有向边的图 #include<iostream> #include<cstdio> #include<cstrin ...
- POJ 3259 Wormholes(SPFA判负环)
题目链接:http://poj.org/problem?id=3259 题目大意是给你n个点,m条双向边,w条负权单向边.问你是否有负环(虫洞). 这个就是spfa判负环的模版题,中间的cnt数组就是 ...
- Poj 3259 Wormholes(spfa判负环)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42366 Accepted: 15560 传送门 Descr ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- poj 1364 King(线性差分约束+超级源点+spfa判负环)
King Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14791 Accepted: 5226 Description ...
- BZOJ 1715: [Usaco2006 Dec]Wormholes 虫洞 DFS版SPFA判负环
Description John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N ...
- LightOj 1221 - Travel Company(spfa判负环)
1221 - Travel Company PDF (English) Statistics problem=1221" style="color:rgb(79,107,114)& ...
随机推荐
- unity编辑器拓展
[ExecutelnEditMode] 在EditMode下也可以执行脚本,Unity默认情况下,脚本只有运行时被执行,加上此属性后,不运行程序也能执行.与PlayMode不同的是函数不会不停 ...
- PowerDesigner 16.5 链接SQL Server 2008R2
链接的目的主要是为了使用PowerDesigner反向工程生成数据字典 Step1: 在Workspace中创建New Physical Data Model, 否则不会出现Database菜单 当链 ...
- Puppeteer入门初探
本文来自网易云社区 作者:唐钊 最近在看 node 爬虫相关的一些东西,我记得还是很久以前常用的 node 爬虫工具还是 superagengt+cherrio,他们的思路是通过发起 http 请求然 ...
- 818. Race Car
Your car starts at position 0 and speed +1 on an infinite number line. (Your car can go into negati ...
- unity网络延迟
using UnityEngine; using System.Collections; public class Test_Ping : MonoBehaviour { public string ...
- 数据库 first
数据库原理 .SQL(DDL.DML) 字符串操作 .数值操作 .日期操作 .空值操作 SQL(基础查询) .SQL(关联查询) SQL(高级查询) 子查询 视图.序列.索引 .约束
- ios swift4之kvo的使用
在swift4之前,使用kvo只需要继承NSObject 就可以了.但是swift4之后发生了变化,必须在class之前加入@objcMembers修饰,不然就没有效果了. 下面举个例子:如定义一个P ...
- truts2标签-forEach标签
<c:forEach begin="1" end="${obj.portnum}" step="1" varStatus=" ...
- JavaScript new Date()IE浏览器下出错 NaN
当涉及到编程,与日期的工作可能是棘手的.然而,幸运的是,大多数语言都已经完成了这个困难的工作,并有一种内置的日期功能来帮助我们.JavaScript是具有有用的功能来帮助大量输出,设置日期. The ...
- 16.Shortest Unsorted Continuous Subarray(最短未排序子数组)
Level: Easy 题目描述: Given an integer array, you need to find one continuous subarray that if you onl ...