2019南昌网络赛 B. Fire-Fighting Hero

B. Fire-Fighting Hero

题目链接:https://nanti.jisuanke.com/t/41349

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 V V (Numbers 1 1 1 to V V V) fire-fighting points in ACM city. These fire-fighting points have E E E roads to communicate with each other. Among them, there is a fire-fighting hero in the S S S fire-fighting point, and the fire-fighting team is distributed in K K 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 \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 ≤ T ≤ 10 ) T (1\le T \le 10) T(1T10), which indicates that there are T T T cases of test data.
The format of each case of test data is as follows:

  • Line 1 1 1 contains five positive integers V ( 1 ≤ V ≤ 1000 ) V (1 \le V \le 1000) V(1V1000), E ( V − 1 ≤ E ≤ V ∗ V 2 ) E (V-1 \le E \le \frac{V*V}{2}) E(V1E2VV), S ( 1 ≤ S ≤ V ) S (1 \le S \le V) S(1SV), K ( 1 ≤ K ≤ V ) K (1\le K \le V) K(1KV) and C ( 1 ≤ C ≤ 10 ) C (1\le C\le 10) C(1C10), the meanings are shown above.
  • Line 2 2 2 contains K K 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 E E line, three positive integers i , j ( 1 ≤ i , j ≤ V ) i, j (1 \le i, j \le V) i,j(1i,jV) and L ( 1 ≤ L ≤ 10000 ) L (1 \le L \le 10000) L(1L10000) per line. Represents a path, i , j i, j i,j as the endpoint (fire-fighting point), L L 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 3

Sample Output

2

题意

T T T组数据,每组数据有 V V V个消防点, E E E条无向边, S S S代表消防英雄所在的消防点,有 K K K支消防队和一个 C C C
然后给你 K K K支消防队所在的消防点和 E E E条无向边。设消防英雄到各消防点最短路径的最大值为 a n s 1 ans1 ans1,消防队到各消防点最短路径的最大值为 a n s 2 ans2 ans2,这里可能会理解错(反正我理解错了 ),换句话说 a n s 2 = m a x { m i n i } ( 1 ≤ i ≤ V ) ans2 = max\{min_i\}(1 \le i \le V) ans2=max{mini}(1iV),其中 m i n i min_i mini代表所有消防队到消防点 i i i的最短路径的最小值。如果 a n s 1 C ≤ a n s 2 \frac{ans1}{C} \le ans2 Cans1ans2就输出 a n s 1 ans1 ans1,否则输出 a n s 2 ans2 ans2
输入保证图联通。

思路

s s s为起点跑一次最短路找到消防英雄到各消防点最短路径的最大值 a n s 1 ans1 ans1,再通过虚拟一个起点来连接 k k k个消防队所在的消防点跑一次最短路找到所有消防队到各消防点最短路径的最大值 a n s 2 ans2 ans2,最后比较 a n s 1 ans1 ans1 a n s 2 ∗ c ans2*c ans2c的大小即可。

代码

#include <bits/stdc++.h>
#define pi acos(-1.0)
#define ll long long
#define ull unsigned long long
#define esp 1e-9
#define inf 0x3f3f3f3f
#define inff 0x3f3f3f3f3f3f3f3f
#define Pair pair<ll, ll>
#define It list<node>::iterator
    
using namespace std;

const ll N = 1e3+5;

struct node{
	ll u, v, dis;
};

struct HeapNode{
	ll dis, u;
	bool operator < (const HeapNode &rhs) const{
		return dis > rhs.dis;
	}
};

struct Dijkstra{
	ll n, dis[N], pre[N], vis[N];
	vector<ll> G[N];
	vector<node> edge;
	void init(ll n){
		this->n = n; edge.clear();
		for (ll i = 0; i <= n; i++){
			G[i].clear();
		}
	}
	void add(ll u, ll v, ll dis){
		edge.push_back((node){u, v, dis});
		G[u].push_back(edge.size()-1);
	}
	void solve(ll s){
		priority_queue<HeapNode> que;
		memset(vis, 0, sizeof(vis));
		for (ll i = 0; i <= n; i++){
			dis[i] = inff;
		}
		dis[s] = 0;
		que.push((HeapNode){0, s});
		while (!que.empty()){
			HeapNode x = que.top(); que.pop();
			ll u = x.u;
			if (!vis[u]){
				vis[u] = true;
				for (ll i = 0; i < G[u].size(); i++){
					node &e = edge[G[u][i]];
					if (dis[e.v] > dis[u]+e.dis){
						dis[e.v] = dis[u]+e.dis;
						pre[e.v] = G[u][i];
						que.push((HeapNode){dis[e.v], e.v});
					}
				}
			}
		}
	}
};

ll arr[N], ans[N];
ll T, n, m, s, k, c, u, v, l, a, b;
Dijkstra dij;

int main(){
	ios::sync_with_stdio(false);
	cin>>T;
	while (T--){
		cin>>n>>m>>s>>k>>c;
		a = b = 0; dij.init(n);
		for (ll i = 1; i <= k; i++){
			cin>>arr[i];
		}
		while (m--){
			cin>>u>>v>>l;
			dij.add(u, v, l); dij.add(v, u, l);
		}
		dij.solve(s);
		for (ll i = 1; i <= n; i++){
			ans[i] = inff;
			a = max(a, dij.dis[i]);
		}
		for (ll i = 1; i <= k; i++){
			dij.add(0, arr[i], 0); dij.add(arr[i], 0, 0);
		}
		dij.solve(0);
		for (ll j = 1; j <= n; j++){
			b = max(b, dij.dis[j]);
		}
		if (a <= b*c){
			cout<<a<<endl;
		}
		else{
			cout<<b<<endl;
		}
	}
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值