zoukankan      html  css  js  c++  java
  • Fire-Fighting Hero (The 2019 Asia Nanchang First Round Online Programming Contest)

    This is an era of team success, but also an era of heroes. Throughout the ages, there have been numerous examples of using the few to defeat the many. There are VV(Numbers 11 to VV) fire-fighting points in ACM city. These fire-fighting points have EEroads to communicate with each other. Among them, there is a fire-fighting hero in the SS fire-fighting point, and the fire-fighting team is distributed in K fire-fighting points. If a fire-fighting point needs to be put out, the fire-fighting hero or the fire-fighting team must arrive as soon as possible, that is, to choose the shortest route to arrive.

    Today, our fire-fighting heroes want to challenge the fire-fighting team. The challenge is to: The maximum value of the shortest path for a fire-fighting hero to go to others fire-fighting points is compared with the maximum value of the shortest path for a fire-fighting team to go to others fire-fighting points from any point in their fire-fighting points. Because firefighting heroes are different and run faster, the maximum value of the shortest path they get should be discounted first, that is, multiplied by a coefficient of frac{1}{C}C1, and then compared. The smaller one wins. Who is the real firefighter in this situation?

    Who is the real firefighter in this situation?

    Input

    The first line contains a positive integer T (1le T le 10)T(1T10), which indicates that there are TT cases of test data.

    The format of each case of test data is as follows:

    • Line 11 contains five positive integers V (1 le V le 1000)V(1V1000), E (V-1 le E le frac{V*V}{2})E(V1E2VV), S (1 le S le V)S(1SV), K (1le K le V)K(1KV) and C (1le Cle 10)C(1C10), the meanings are shown above.
    • Line 22 contains KK positive integers, which in turn denotes the location number of the fire-fighting point where the fire-fighting team is located.

    In the next EE line, three positive integers i, j (1 le i, j le V)i,j(1i,jV) and L (1 le L le 10000)L(1L10000) per line. Represents a path, i, ji,j as the endpoint (fire-fighting point), LL as the length of the path.

    Output

    Each case of test data outputs one line, which is a integer. That is, the maximum value of the shortest path of the winner (If the fire hero wins, the maximum value before the discount should be output). A draw is also a victory for fire-fighting hero.

    样例输入

    1
    4 7 3 2 2
    1 4
    1 2 7
    1 3 2
    1 4 6 
    2 1 1
    2 4 1
    3 2 1
    3 4 3

    样例输出

    2
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<stack>
    using namespace std;
    typedef long long ll;
    ll a[1005];
    ll dp[1005][1005];
    const ll inf=1e17;
    ll head[1005];
    struct node
    {
        ll k;
        ll step;
        ll next;
    } e[1000005];
    ll tol;
    bool vis[1005];
    inline void add(int x,int y,int z)
    {
        e[tol].next=head[x];
        e[tol].k=y;
        e[tol].step=z;
        head[x]=tol++;
        e[tol].next=head[y];
        e[tol].k=x;
        e[tol].step=z;
        head[y]=tol++;
    }
    ll n,k;
    bool operator <(const node &x,const node &y)
    {
        return y.step<x.step;
    }
    ll ans1,ans2;
    void dij1(ll x)
    {
        node r,p;
        p.step=0;
        p.k=x;
        priority_queue<node>q;
        for(ll i=1; i<=n; i++)
            vis[i]=false;
        q.push(p);
        while(!q.empty())
        {
            p=q.top();
            q.pop();
            if(vis[p.k])
                continue;
            vis[p.k]=true;
            ans1=max(p.step,ans1);
            for(ll i=head[p.k]; i!=-1; i=e[i].next)
            {
                if(!vis[e[i].k])
                {
                    r.k=e[i].k;
                    r.step=p.step+e[i].step;
                    q.push(r);
                }
            }
        }
    }
    void dij2()
    {
        node r,p;
        ll i;
        priority_queue<node>q;
        for(i=1; i<=n; i++)
            vis[i]=false;
        for(i=1; i<=k; i++)
        {
            p.k=a[i];
            p.step=0;
            q.push(p);
        }
        while(!q.empty())
        {
            p=q.top();
            q.pop();
            if(vis[p.k])
                continue;
            vis[p.k]=true;
            ans2=max(p.step,ans2);
            for(i=head[p.k]; i!=-1; i=e[i].next)
            {
                if(!vis[e[i].k])
                {
                    r.k=e[i].k;
                    r.step=p.step+e[i].step;
                    q.push(r);
                }
            }
        }
    }
    int main()
    {
        ll i,j,m,l,r,q,t,c,x,y,s;
        scanf("%lld",&t);
        while(t--)
        {
            scanf("%lld %lld %lld %lld %lld",&n,&m,&s,&k,&c);
            for(i=1; i<=k; i++)
                scanf("%lld",&a[i]);
            tol=0;
            for(i=1; i<=n; i++)
                head[i]=-1;
            for(i=1; i<=m; i++)
            {
                scanf("%lld %lld %lld",&x,&y,&l);
                add(x,y,l);
            }
            ans1=-1;
            dij1(s);//消防英雄
            ans2=-1;//消防员
            dij2();
            ll min1;
            if(ans1<=ans2*c)
                printf("%lld
    ",ans1);
            else
                printf("%lld
    ",ans2);
        }
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    js window对象属相和方法相关整理资料
    js中把字符串转换成number格式方法
    oracle中CAST函数使用简介【转】
    Oracle使用SQL语句修改字段类型
    @GeneratorValue与@GenericGenerator注解使用心得
    @Column 注解详情
    Spring中的注入方式 和使用的注解 详解
    maven教程
    wxpyhon 对话框
    wxpython 按钮等事件的触发
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11488539.html
Copyright © 2011-2022 走看看