图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven

  •  131072K
 

One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are NN spots in the jail and MM roads connecting some of the spots. JOJO finds that Pucci knows the route of the former (K-1)(K1)-th shortest path. If Pucci spots JOJO in one of these K-1K1 routes, Pucci will use his stand Whitesnake and put the disk into JOJO's body, which means JOJO won't be able to make it to the destination. So, JOJO needs to take the KK-th quickest path to get to the destination. What's more, JOJO only has TT units of time, so she needs to hurry.

JOJO starts from spot SS, and the destination is numbered EE. It is possible that JOJO's path contains any spot more than one time. Please tell JOJO whether she can make arrive at the destination using no more than TT units of time.

Input

There are at most 5050 test cases.

The first line contains two integers NN and M(1 leq N leq 1000, 0 leq M leq 10000)(1N1000,0M10000). Stations are numbered from 11 to NN.

The second line contains four numbers S, E, KS,E,K and TT ( 1 leq S,E leq N1S,EN, S eq ESE, 1 leq K leq 100001K10000, 1 leq T leq 1000000001T100000000 ).

Then MM lines follows, each line containing three numbers U, VU,V and W(1 leq U,V leq N, 1 leq W leq 1000)(1U,VN,1W1000) . It shows that there is a directed road from UU-th spot to VV-th spot with time WW.

It is guaranteed that for any two spots there will be only one directed road from spot AA to spot B(1 leq A,B leq N, A eq B)(1A,BN,AB), but it is possible that both directed road <A,B><A,B> and directed road <B,A><B,A>exist.

All the test cases are generated randomly.

Output

One line containing a sentence. If it is possible for JOJO to arrive at the destination in time, output "yareyaredawa" (without quote), else output "Whitesnake!" (without quote).

样例输入

2 2
1 2 2 14
1 2 5
2 1 4

样例输出

yareyaredawa

题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

//图上两点之间的第k最短路径的长度

 1 #define  P pair<int,int>
 2 #define  ph push_back
 3 #define  N 1009
 4 #define  M 10009
 5 const int inf =0x3f3f3f3f;
 6 int n,m,s,e,k,t;
 7 int dis[N];
 8 vector<P>ve[N],se[N];
 9 void  init()
10 {
11     for(int i=0;i<n;i++) {
12         ve[i].clear();
13         se[i].clear();
14     }
15 }
16 struct Node{
17     int to,w;
18     bool operator <(const Node&a)const{
19         return w+dis[to]>a.w+dis[a.to];
20     }
21 };
22 void dijk()
23 {
24     priority_queue<P,vector<P>,greater<P> >que;
25     for(int i=0;i<N;i++) dis[i]=inf;
26     dis[e]=0;
27     que.push({0,e});
28     while(!que.empty()){
29         P temp=que.top();que.pop();
30         int v=temp.second;
31         if(dis[v]<temp.first) continue;
32         for(int i=0;i<se[v].size();i++){//反向边
33             P p=se[v][i];
34             int x=p.first,w=p.second;
35             if(dis[x]>dis[v]+w){
36                 dis[x]=dis[v]+w;
37                 que.push({dis[x],x});
38             }
39         }
40     }
41 }
42 int astar()
43 {
44     priority_queue<Node>que;
45     que.push({s,0});
46     k--;
47     while(!que.empty()){
48         Node temp=que.top();que.pop();
49         int v=temp.to;
50         if(v==e) {
51             if(k) k--; 
52             else return temp.w;
53         }
54         for(int i=0;i<ve[v].size();i++){
55             P p=ve[v][i];
56             int x=p.first,w=p.second;
57             que.push({x,w+temp.w});
58         }
59     }
60     return -1;
61 }
62 int  main()
63 {
64     while(~scanf("%d%d",&n,&m)){
65         scanf("%d%d%d%d",&s,&e,&k,&t);
66         int u,v,w;
67         for(int i=0;i<m;i++)
68         {
69             scanf("%d%d%d",&u,&v,&w);
70             ve[u].ph({v,w});
71             se[v].ph({u,w});
72         }
73         dijk();
74         if(dis[s]==inf) printf("Whitesnake!
");
75         else{
76             if(s==e) k++;//k+1
77             int ans=astar();
78             if(ans<=t&&ans!=-1) printf("yareyaredawa
");
79             else{
80                 printf("Whitesnake!
");
81             }
82         }
83     }
84     return   0;
85 }
原文地址:https://www.cnblogs.com/tingtin/p/9649256.html