Made In Heaven

1 篇文章 0 订阅
1 篇文章 0 订阅

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 NNN spots in the jail and MMM roads connecting some of the spots. JOJO finds that Pucci knows the route of the former (K−1)(K-1)(K−1)-th shortest path. If Pucci spots JOJO in one of these K−1K-1K−1 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 KKK-th quickest path to get to the destination. What's more, JOJO only has TTT units of time, so she needs to hurry.

JOJO starts from spot SSS, and the destination is numbered EEE. 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 TTT units of time.

Input

There are at most 505050 test cases.

The first line contains two integers NNN and MMM (1≤N≤1000,0≤M≤10000)(1 \leq N \leq 1000, 0 \leq M \leq 10000)(1≤N≤1000,0≤M≤10000). Stations are numbered from 111 to NNN.

The second line contains four numbers S,E,KS, E, KS,E,K and TTT ( 1≤S,E≤N1 \leq S,E \leq N1≤S,E≤N, S≠ES \neq ES≠E, 1≤K≤100001 \leq K \leq 100001≤K≤10000, 1≤T≤1000000001 \leq T \leq 1000000001≤T≤100000000 ).

Then MMM lines follows, each line containing three numbers U,VU, VU,V and WWW (1≤U,V≤N,1≤W≤1000)(1 \leq U,V \leq N, 1 \leq W \leq 1000)(1≤U,V≤N,1≤W≤1000) . It shows that there is a directed road from UUU-th spot to VVV-th spot with time WWW.

It is guaranteed that for any two spots there will be only one directed road from spot AAA to spot BBB (1≤A,B≤N,A≠B)(1 \leq A,B \leq N, A \neq B)(1≤A,B≤N,A≠B), but it is possible that both directed road <A,B><A,B><A,B> and directed road <B,A><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 沈阳赛区网络预赛

#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
    int v,c,w;
    node (int _v=0,int _c=0,int _w=0):v(_v),c(_c),w(_w) {}
    bool operator <(const node &r)const
    {
        return c>r.c;
    }
};
struct Edge
{
    int v,cost;
    Edge(int _v=0,int _cost=0):v(_v),cost(_cost) {}
};
vector<Edge>E[10009];
bool vis[10009];
int dis[10009];
void Dijkstra(int n,int start)
{
    memset(vis,0,sizeof(vis));
    for(int i=1; i<=n; i++)dis[i]=inf;
    priority_queue<node>q;
    while(!q.empty()) q.pop();
    dis[start]=0;
    q.push(node(start,0,0));
    node tmp;
    while(!q.empty())
    {
        tmp=q.top();
        q.pop();
        int u=tmp.v;
        if(vis[u])continue;
        vis[u]=true;
        for(int i=0; i<(int)E[u].size(); i++)
        {
            int v=E[tmp.v][i].v;
            int cost=E[u][i].cost;
            if(!vis[v]&&dis[v]>dis[u]+cost)
            {
                dis[v]=dis[u]+cost;
                q.push(node(v,dis[v],0));
            }
        }
    }
}
void added(int u,int v,int w)
{
    E[u].push_back(Edge(v,w));
}
int A_star(int n,int start,int End,int k,int t)
{
    priority_queue<node>q;
    while(!q.empty())q.pop();
    q.push(node(start,dis[start],0));
    node tmp;
    int cnt=0;
    while(!q.empty())
    {
        tmp=q.top();
        q.pop();
        int u=tmp.v;
        if(tmp.c>t)return inf;
        if(tmp.v==End)
        {
            cnt++;
            if(cnt==k)return tmp.c;
        }
        for(int i=0; i<(int)E[u].size(); i++)
        {
            int v=E[u][i].v;
            int cost=E[u][i].cost;
            q.push(node(v,tmp.w+cost+dis[v],tmp.w+cost));
        }
    }
    return inf;
}
int main()
{
    int n,m,s,e,k,t,v[100009],u[100009],w[100009];
    while(~scanf("%d %d",&n,&m))
    {
        scanf("%d %d %d %d",&s,&e,&k,&t);
        for(int i=1; i<=n; i++)
        {
            E[i].clear();
        }
        for(int i=1; i<=m; i++)
        {
            scanf("%d %d %d",&v[i],&u[i],&w[i]);
            added(u[i],v[i],w[i]);
        }
        Dijkstra(n,e);
        for(int i=1; i<=n; i++)
        {
            E[i].clear();
        }
        for(int i=1; i<=m; i++)
        {
            added(v[i],u[i],w[i]);
        }
        int U=A_star(n,s,e,k,t);
        if(U<=t)
        {
            printf("yareyaredawa\n");
        }
        else
        {
            printf("Whitesnake!\n");
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值