Problem Description
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 V (Numbers 1 to V) fire-fighting points in ACM city. These fire-fighting points have EE roads to communicate with each other. Among them, there is a fire-fighting hero in the S 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 1/C, 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≤T≤10), which indicates that there are T cases of test data.
The format of each case of test data is as follows:
- Line 1 contains five positive integers V(1≤V≤1000), E(V−1≤E≤2V∗V), S(1≤S≤V), K(1≤K≤V) and C(1≤C≤10), the meanings are shown above.
- Line 2 contains K positive integers, which in turn denotes the location number of the fire-fighting point where the fire-fighting team is located.
In the next E line, three positive integers i,j(1≤i,j≤V) and L(1≤L≤10000) per line. Represents a path, i,j as the endpoint (fire-fighting point), L 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.
Sample Input
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 3Sample Output
2
题意:
给出 n 个点 m 条边的无环无向连通图,每一个点代表一个着火点,有 1 个位于 S 点的消防英雄和 k 个消防队进行救火
对于消防英雄来说,其到每个点的最短路中的最大值除以给出的 C 是其花费
对于消防队来说,要从 k 的队伍中选花费最小的队伍,即到每个着火点的最短路中的最大值
现在要判断两者花费谁更小,如果消防英雄获胜,输出消防英雄除以 C 前的花费,如果消防队获胜,输出最小花费,如果平局,算消防英雄获胜
思路:唯一的难点在题意,读明白题后跑 Floyd 即可
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL quickModPow(LL a,LL b,LL mod){ LL res=1; a=a%mod; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1;} return res; }
LL getInv(LL a,LL mod){ return quickModPow(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-10;
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int pos[N];
int G[N][N];
void init(int n){
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(i!=j) {
G[i][j]=INF;
G[j][i]=INF;
}
else {
G[i][j]=0;
G[j][i]=0;
}
}
}
}
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n,m;
int S,k,C;
scanf("%d%d",&n,&m);
scanf("%d%d%d",&S,&k,&C);
for(int i=1; i<=k; i++)
scanf("%d",&pos[i]);
init(n);
for(int i=1; i<=m; i++) {
int x,y,w;
scanf("%d%d%d",&x,&y,&w);
if( G[x][y]>w || G[y][x]>w) {
G[x][y]=w;
G[y][x]=w;
}
}
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
int maxx2=0;
for(int j=1; j<=n; j++)
maxx2=max(maxx2,G[S][j]);
for(int i=1;i<=k;++i) {
for(int j=1;j<=k;++j) {
G[pos[i]][pos[j]]=0;
G[pos[j]][pos[i]]=0;
}
}
int maxx1=0;
for(int i=1; i<=n; i++) {
int maxxn=INF;
for(int j=1; j<=k; j++)
maxxn=min(maxxn,G[pos[j]][i]);
maxx1=max(maxx1,maxxn);
}
LL y1=1LL*maxx2;
LL x1=1LL*C*maxx1;
if(y1<=x1)
printf("%d\n",maxx2);
else
printf("%d\n",maxx1);
}
return 0;
}