SPFA Judgement Negative ring

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.