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 (1\le T \le 10)T(1≤T≤10), 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(1≤V≤1000), E (V-1 \le E \le \frac{V*V}{2})E(V−1≤E≤2V∗V?), S (1 \le S \le V)S(1≤S≤V), K (1\le K \le V)K(1≤K≤V) and C (1\le C\le 10)C(1≤C≤10), 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(1≤i,j≤V) and L (1 \le L \le 10000)L(1≤L≤10000) 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\n",ans1);
        else
            printf("%lld\n",ans2);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Shallow-dream/p/11488539.html

时间: 2024-08-30 16:40:54

Fire-Fighting Hero (The 2019 Asia Nanchang First Round Online Programming Contest)的相关文章

H. The Nth Item(The 2019 Asia Nanchang First Round Online Programming Contest)

题意:https://nanti.jisuanke.com/t/41355 给出N1,计算公式:A=F(N)Ni=Ni-1 ^ (A*A),F为类斐波那契需要矩阵快速幂的递推式. 求第k个N. 思路: 发现从大约1e5个数开始N交替出现,到一定位置%2即可.(or正解:https://blog.csdn.net/qq_41848675/article/details/100667808   or https://blog.csdn.net/jk_chen_acmer/article/detail

Pangu Separates Heaven and Earth(签到题)(The 2019 Asia Nanchang First Round Online Programming Contest)

Long long ago, the sky and the earth were not separated, and the universe was chaotic. There was a giant named Pangu who slept for eighteen thousand years in this chaos. One day, Pangu woke up suddenly. When he saw the darkness around him, he took up

The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master

题目链接:https://nanti.jisuanke.com/t/41352 题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了.其实就是个水题,反向模拟就好了, 用队列模拟,反向模拟,它要放m张卡到后面,那我就放m张卡到前面,一开始队列只有1张卡,慢慢加到n张卡, 先加大的卡,再一直到1的卡.对了,可能会出现只有5张卡,m却是6,7,8或9,10,那么为了减少不必要的模拟, 用mod来减少,因为有些模拟会让卡和之前比较,算是原封不动. 1 #include <iostream> 2

The 2019 Asia Nanchang First Round Online Programming Contest The Nth Item

The Nth Item 思路: 先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出. 但是还不够,我们先对\(n\)欧拉降幂,然后求base为\(\sqrt{1e9}\)的快速幂,预处理一些东西,就可以类似O(1)求出了. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/std

The 2019 Aisa Nanchang First Round Online Programming Contest ——H

思路:矩阵快速幂+map 代码: #include<cmath> #include<algorithm> #include<cstdio> #include<map> const int INF=0x3f3f3f3f; const int maxn = 1e7+10; const int mod=998244353; using namespace std; typedef long long ll; map<ll,ll> mp; ll n; s

The 2019 Asia Yinchuan First Round Online Programming F. Moving On

t题目链接:https://nanti.jisuanke.com/t/41290 思路:题目意思很容易想到floyd,但是由于危险度的限制,我们该怎么跑floyd呢. 一开始理解错题目了,以为u->v包括终点起点都不能超过给的危险度,不过看样例,好像只需要中间的城市不能超过危险度. 我们可以这么想,每个城市都有一个危险度,而floyd算法的本质是i到j经过前k个城市的转移,得到多源最短路,那么我们不妨 记录城市的编号和危险度,然后按城市的危险度排序,重新编号,危险度小的先跑floyd,然后f[k

2019 ICPC Universidad Nacional de Colombia Programming Contest

https://codeforc.es/gym/102307 最后5题收尾了,大概率铜.其中有2题是签到手速题.有一题是抄模板的表达式求值,写一个分数类随便过. 比较有趣的是下面的: G. Graduation 题意:一共有n门课,每门课有至多1门先修课,没有先修课的用0表示.学习一门课的条件是:这个学期选的课不足k门,且这门课的先修课(假如有的话)已经在前面的学期中学过了.求最少需要多少个学期学完. 思路:队友一开始是优先拓展儿子数最多的子结点,我觉得怪怪的,比如一个像蒲公英一样的东西,一开始

线程编程指南(Threading Programming Guide)

简介 线程是一种技术,可以在一个应用中同时执行多个代码路径.尽管新技术如操作对象和GCD提供一个更现代和更高效的工具来实现并发,OS X 和iOS也提供接口来创建和管理线程. 本文揭示了OS X中可用的线程包并展示了如何使用它们.本文还描述了应用程序中支持线程和多线程代码同步的相关技术. 重要:如果你正在开发一个新的应用,鼓励你研究实现并发的OS X技术.尤其是你不熟悉实现线程应用所需要的设计技术.这些可选择的技术简化你实现执行并发路径的工作量并提供相对传统线程更好的性能.关于这些技术的信息,参

HDU 4901(杭电多校训练#3 1005题)The Romantic Hero(DP)

题目地址:HDU 4901 这题没想到最后居然能够做出来.... 这题用了两次DP,先从前往后求一次异或的,再从后往前求一次与运算的.分别是 1:求异或的时候,定义二维数组huo[1000][1024],前者指第几位,后者是哈希的思想,若huo[x][y]=2则表示最右边的数为第x位时,异或值为y的出现了两次,需要再定义一个hash数组,来保存前面出现的所有情况,再找有多少位的时候,用hash数组中出现的所有的值与当前的第x位的数字进行异或. 2:求与的时候,定义二维数组yu[1000][102