Fire-Fighting Hero (The 2019 Asia Nanchang First Round Online Programming Contest)
Posted shallow-dream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 \frac1CC1?, 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 \fracV*V2)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;
以上是关于Fire-Fighting Hero (The 2019 Asia Nanchang First Round Online Programming Contest)的主要内容,如果未能解决你的问题,请参考以下文章
HDU 4901 The Romantic Hero 题解——S.B.S.