Meeting in the Middle
InterviewTime limit1sMemory limit512 MB
Given a directed weighted graph and a set of K home cities, pick every city X such that the maximum over all homes of the round-trip distance to X and back is minimized, printing the chosen city numbers in ascending order.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Brute force, Implementation
- Solved
- No attempts yet
Problem
Junhyung has arranged to meet his friends tomorrow. Junhyung and his friends live in different cities.
The roads connecting the cities are one-way only, so the time to travel from city to city may differ from the time to travel from city to city .
Junhyung and his friends want to choose a city that satisfies the conditions below and meet there.
- The round-trip time is the sum of the time to travel from one's home city to city and the time to travel from city back to one's home city.
- They only choose a city that Junhyung and his friends can reach using the roads.
- They choose the city that minimizes the maximum of the round-trip times of Junhyung and his friends.
- It is guaranteed that there is at least one city that Junhyung and his friends can travel to.
There are many cities, so this is hard to compute. Let us tell Junhyung and his friends the city on their behalf.
Input
The first line gives the number of cities and the number of roads .
From the second line to line , the city , the city , and the time it takes to travel from city to city are given, separated by spaces.
Line gives the total number of people, Junhyung and his friends, .
Line gives the numbers of the cities where Junhyung and his friends live, separated by spaces.
Output
Print the number of the city that satisfies the conditions above. If there are multiple possible cities , print the city numbers in ascending order.