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?
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:
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.
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)
原文:https://www.cnblogs.com/Shallow-dream/p/11488539.html