HDU 4076 haunted graveyard-spfa (negative weight loop)

Source: Internet
Author: User
/* HDU 4076 haunted graveyard-spfa (negative weight loop) Question: There are N * m points, each point can go in four directions, and some points cannot go in the cemetery, some points are cave. When you reach this point, it will be transferred to another point. The time spent may be a positive number, a negative number, or 0. The starting point is (0, 0), and the destination is (N-1 m-1). The question ensures that the starting point and ending point are not the cemetery or the cave. If it is possible that it will never reach the end point, that is, the graph has a negative weight loop and outputs The never; otherwise, the output will take the least time or impossible; idea: if there is a negative weight, it is obvious that spfa is used. When the number of relaxation times for a certain point Times out, the number of vertices in the graph is N * m, which indicates there is a negative weight loop. However, you must note that the end point cannot be included when determining the negative weight loop, because the end point will not be relaxed when it first reaches the end point. */# Include <iostream> # include <cstring> # include <queue> using namespace STD; # define INF 0 xfffffffconst int n = 35; int map [N] [N], XX [N] [N], YY [N] [N], TT [N] [N], DIST [N] [N], vis [N] [N], CNT [N] [N]; int dir [4] [2] = {}, {0,-1 }}; int W, H, flag; struct node {int X, Y ;}; void spfa () {int I, j, ans; for (I = 0; I <W; ++ I) {for (j = 0; j 

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.