vijos:p1082 Jungle Adventure

Source: Internet
Author: User

Describe

There is a mysterious jungle in the Great Rift Valley, the world's Explorer Paradise, the famous yellow skin Explorer BB has always wanted to try. Just as our scientists will be the first to conduct a scientific examination of the Great Rift Valley in April 2005, BB decided to follow the expedition team to explore the mysterious jungle. Prior to his departure, he collected information about the mysterious jungle expedition and plotted it as a map with a number of security points (including entry points and exit points), numbered 1, 2 、...、 N; if one of the security points is directly connected to another security point, it is marked with an edge The graph is a connected graph (with at least one path between any two points), and the length of each road on the map is marked by the amount of energy required to take the road.

KK walks at a speed of 1 and knows its physical strength is K. He wanted to know whether he could successfully cross the jungle, depending on his physical condition.

Format input Format

The first line is two integers n (<=5000) m (<=40000), which indicates the number of safe points on the map and the numbers of edges respectively;
Line 2nd to m+1 line 4 integers x y c d,x, y for two points with direct link edge, C go this road need to expend energy; d denotes the length of the Edge; (where 150<=c,d<=300)
Line m+2 Two integer s T, respectively, indicating the safe entry point and the number of the exit point;
Line m+3 An integer K, indicating the physical value of BB; (k<10^9)
Multiple data on the same line is separated by a space.

Output format

An integer, if BB can safely exit through the jungle such as the entrance, output the shortest time, otherwise output-1

Input:

4 5
1 2 2 3
1 3 3 5
1 4 7 10
2 4 4 6
3 4 2 6
1 4
5

Output

11

The shortest circuit, add a limit condition.

#include <cstdio>#include<cstring>#include<vector>#include<queue>using namespacestd;Const intmaxn=5005;Const intinf=0x3f3f3f3f;structnode{intv,dist,w; intPOW; Node () {} node (intVintDistintW) { This->v=v;  This->dist=Dist;  This->w=W; }};vector<Node>MP[MAXN];intn,m;intD[MAXN],VIS[MAXN];intPOW[MAXN];//indicates how much energy is left after reaching that point.intPower;voidSPFA (ints) {     for(intI=1; i<=n;i++) {D[i]=INF; Vis[i]=0; } Queue<int>que;    Que.push (s); Vis[s]=1; D[s]=0; Pow[s]=Power;  while(!Que.empty ()) {        intnow=Que.front (); Que.pop (); Vis[now]=0;  for(intI=0; I<mp[now].size (); i++) {Node e=Mp[now][i]; if(d[e.v]>d[now]+e.dist&&pow[now]>=e.w) {D[E.V]=d[now]+e.dist; POW[E.V]=pow[now]-E.W; if(!VIS[E.V])                    {Que.push (E.V); VIS[E.V]=1; }            }        }    }    }intMain () {scanf ("%d%d",&n,&m);  for(intI=0; i<m;i++)    {        intu,v,dist,w; scanf ("%d%d%d%d",&u,&v,&w,&Dist);        Mp[u].push_back (Node (v,dist,w));    Mp[v].push_back (Node (u,dist,w)); }    intST,GL; scanf ("%d%d",&st,&GL); scanf ("%d",&power);    SPFA (ST); if(d[gl]==INF) printf ("-1\n"); Elseprintf ("%d\n", D[GL]); return 0;} 

vijos:p1082 Jungle Adventure

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.