CF852D.Exploration plan

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The competitors of Bubble Cup X gathered after the competition and discussed what is the best way to get to know the host country and its cities.

After exploring the map of Serbia for a while, the competitors came up with the following facts: the country has VV cities which are indexed with numbers from 11 to VV , and there are EE bi-directional roads that connect the cites. Each road has a weight (the time needed to cross that road). There are NN teams at the Bubble Cup and the competitors came up with the following plan: each of the NN teams will start their journey in one of the VV cities, and some of the teams share the starting position.

They want to find the shortest time TT , such that every team can move in these TT minutes, and the number of different cities they end up in is at least KK (because they will only get to know the cities they end up in). A team doesn't have to be on the move all the time, if they like it in a particular city, they can stay there and wait for the time to pass.

Please help the competitors to determine the shortest time TT so it's possible for them to end up in at least KK different cities or print -1 if that is impossible no matter how they move.

Note that there can exist multiple roads between some cities.

输入格式

The first line contains four integers: VV , EE , NN and K (1<=V<=600, 1<=E<=20000, 1<=N<=min(V,200), 1<=K<=N)K\ (1<=V<=600,\ 1<=E<=20000,\ 1<=N<=min(V,200),\ 1<=K<=N) , number of cities, number of roads, number of teams and the smallest number of different cities they need to end up in, respectively.

The second line contains NN integers, the cities where the teams start their journey.

Next EE lines contain information about the roads in following format: Ai Bi Ti (1<=Ai,Bi<=V, 1<=Ti<=10000)A_{i}\ B_{i}\ T_{i}\ (1<=A_{i},B_{i}<=V,\ 1<=T_{i}<=10000) , which means that there is a road connecting cities AiA_{i} and BiB_{i} , and you need TiT_{i} minutes to cross that road.

输出格式

Output a single integer that represents the minimal time the teams can move for, such that they end up in at least KK different cities or output -1 if there is no solution.

If the solution exists, result will be no greater than 17313111731311 .

输入输出样例

  • 输入#1

    6 7 5 4
    5 5 2 2 5
    1 3 3
    1 5 2
    1 6 5
    2 5 4
    2 6 7
    3 4 11
    3 5 3
    

    输出#1

    3

说明/提示

Three teams start from city 5, and two teams start from city 2. If they agree to move for 3 minutes, one possible situation would be the following: Two teams in city 2, one team in city 5, one team in city 3 , and one team in city 1. And we see that there are four different cities the teams end their journey at.

首页