题目题解代码
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. 就是让找有没有负权回路,因为只要有负权回路,FJ就一定可以在0时刻之前回到起点
判断有没有负权回路,用Bellman_ford 过程:做n次循环每一条边,判断是否可以用它更新到某个点的最短路 然后判断是不是存在一条边每加一次都可以让最短路变小,若存在,则存在负权回路
新闻热点
疑难解答