Will SPFA so long time unexpectedly will not judge negative ring, just back today.
"Example" poj3259
The main idea: when the farmer John was reclaiming his farm, he found many strange insect caves. These insect holes are unidirectional and can send you from the inlet to the exit and make the time go backwards for some time. Each of John's farms contains n (1≤n≤500) blocks, numbered from 1~n, which have M (1≤m≤2500) roads, and W (1≤w≤200) insect holes between the n plots. Because John is an avid time traveler, he wants to try something like this: starting from a piece of land, going back to the starting point through some path and insect hole, and time is earlier than the departure time, so maybe he can meet himself. Your task is to help John determine whether it is feasible. He will provide a complete map of his F (1≤f≤5) farm. Each road will take no more than 10,000 seconds to complete, and each insect hole will go backwards for no more than 10,000 seconds.
Solution
Think about it will find that this problem is actually judging the negative ring in the chart. This feature can be implemented SPFA. First if a point in the SPFA in the team more than n times, it shows that there is a negative ring in the figure, as to why the queue n times instead of being updated n times, you can assume a graph with two nodes. There are 10 heavy edges from 1-2. Benquan from 10 to 1 respectively. It is then entirely possible to traverse the time from the edge of the edge of 10 to start updating 10 times. However, there can be no negative power loop.
SPFA Judgement Negative ring