Made In Heaven

//该题与poj2449 基本相同 

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <functional>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
int vis[1005];
int low[1005];
int head[1005],head1[1005];
int from,to;
int tot;
int n,m,k;
struct edge
{
    int u,v;
    int len;
    int next;       //正向
    int next1;      //反向
    edge() {}
    edge(int x,int y,int c):u(x),v(y),len(c) {}
};
edge p[100005];

struct node
{
    int po;
    int g,h;
    node() {}
    node(int x,int y,int z):po(x),g(y),h(z) {}
    bool operator<(const node& a)const
    {
        return g+h>a.g+a.h;
    }
};

void add_edge(int u,int v,int c)
{
    p[tot] = edge(u,v,c);
    p[tot].next = head[u];
    head[u] = tot;
    p[tot].next1 = head1[v];
    head1[v] = tot++;
}

void  work(int c)       //从to开始找出所有点到to的最短路
{
    priority_queue<node>que;
    memset(vis,0,sizeof(vis));
    for(int i = 1; i <= n; i++)
        low[i] = INF;
    low[c] = 0;
    que.push(node(c,0,0));
    while(!que.empty())
    {
        node cur = que.top();
        que.pop();
        if(vis[cur.po])
            continue;
        vis[cur.po] = 1;
        for(int i = head1[cur.po]; ~i; i = p[i].next1)       //反向查找
        {
            if(low[p[i].u] > low[cur.po]+p[i].len)
            {
                low[p[i].u] = low[cur.po] + p[i].len;
                que.push(node(p[i].u,0,low[p[i].u]));
            }
        }
    }
}


int bfs(int t)
{
    int num = 0;
    priority_queue<node>que;
    node cur;
    cur.po = t;
    cur.g = 0;
    que.push(cur);
    while(!que.empty())
    {
        cur = que.top();
        que.pop();
        int tp = cur.po;
        if(tp == to)
        {
            num ++;
            if(num == k)
            {
                return cur.g;
            }
        }
        for(int i = head[cur.po]; ~i; i = p[i].next)
        {
            node tmp;
            int x = p[i].v;
            tmp.po = x;
            tmp.g = cur.g + p[i].len;
            tmp.h = low[x];
            que.push(tmp);
        }
    }
    return -1;
}

void ini()
{
    tot = 0;
    memset(head,-1,sizeof(head));
    memset(head1,-1,sizeof(head1));
}

int main()
{
    int a,b,len, t;
    while(scanf("%d%d",&n,&m) != EOF)
    {
        ini();
        scanf("%d%d%d%d",&from,&to,&k, &t);
        for(int i = 0; i < m; i++)
        {
            scanf("%d%d%d",&a,&b,&len);
            add_edge(a,b,len);
        }

        work(to);
        if(low[from] == INF)   //如果from不能到达to
        {
            printf("Whitesnake!\n");
            continue;
        }
        if(from == to)
        {
            k++;
        }
        printf("%s\n",(bfs(from)<=t) ? "yareyaredawa" :"Whitesnake!");
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值