zoukankan      html  css  js  c++  java
  • ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven

    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 MM (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,ENS eq ESE1 leq K leq 100001K100001 leq T leq 1000000001T100000000 ).

    Then MM lines follows, each line containing three numbers U, VU,V and WW (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 BB (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 沈阳赛区网络预赛

    A*算法求第k短路径,先预处理下以t为起点的到其它点的最短路径,而A*算法中优先队列是按w+dist[v] 从小到大排序的,dist[v]表示从t到v的距离,w表示从s到v的距离,这样第k次找到的路径就是第k短了。

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 #define INF 0x3f3f3f3f
     4 using namespace std;
     5 const int N = 1e3+10;
     6 const int M = 1e4+10;
     7 int n, m, s, e, k, t;
     8 typedef pair<int,int> P;
     9 vector<P> vs[N], rvs[N];
    10 int dist[N];
    11 struct Nod{
    12     int v, w;
    13     bool operator < (const Nod &a) const{
    14         return w+dist[v] > a.w+dist[a.v];
    15     }
    16 };
    17 void dij() {
    18     priority_queue<P, vector<P>, greater<P> >que;
    19     memset(dist, INF, sizeof(dist));
    20     dist[e] = 0;
    21     que.push(P(0,e));
    22     while(que.size()) {
    23         P p = que.top(); que.pop();
    24         if(dist[p.second] < p.first) continue;
    25         for(auto q:rvs[p.second]) {
    26             int v = q.first, w = q.second;
    27             if(dist[v] > dist[p.second] + w) {
    28                 dist[v] = dist[p.second] + w;
    29                 que.push(P(dist[v],v));
    30             }
    31         }
    32     }
    33 }
    34 int Astart() {
    35     priority_queue<Nod> que;
    36     que.push((Nod){s,0});
    37     k--;
    38     while(que.size()) {
    39         Nod ee = que.top(); que.pop();
    40         if(ee.v == e) {
    41             if(k) k--;
    42             else return ee.w;
    43         }
    44         for(auto E:vs[ee.v]) {
    45             int u = E.first, w = E.second;
    46             que.push((Nod){u,ee.w+w});
    47         }
    48     }
    49     return -1;
    50 }
    51 int main() {
    52     while(scanf("%d%d", &n, &m) != EOF) {
    53         scanf("%d%d%d%d",&s,&e,&k,&t);
    54         for(int i = 1; i <= n; i ++) vs[i].clear(), rvs[i].clear();
    55         for(int i = 1; i <= m; i ++) {
    56             int u, v, w;
    57             scanf("%d%d%d", &u, &v, &w);
    58             vs[u].push_back(P(v,w));
    59             rvs[v].push_back(P(u,w));
    60         }
    61         dij();
    62         if(dist[s] == INF) printf("Whitesnake!
    ");
    63         else {
    64             if(s == e) k++;
    65             int ans = Astart();
    66             if(ans <= t && ans != -1) printf("yareyaredawa
    ");
    67             else printf("Whitesnake!
    ");
    68         }
    69     }
    70     return 0;
    71 }
  • 相关阅读:
    k8s学习笔记之五:Pod资源清单spec字段常用字段及含义
    k8s学习笔记之四:资源清单定义入门
    k8s学习笔记之三:k8s快速入门
    k8s学习笔记之一:kubernetes简介
    k8s学习笔记之二:使用kubeadm安装k8s集群
    centos7安装elasticsearch6.3.x集群并破解安装x-pack
    Centos6搭建sftp服务器
    底层互害模式,深契民心
    你不视我为子女,我凭什么视你为父母
    nodejs的桌面应用(electron)
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/9610777.html
Copyright © 2011-2022 走看看