Farthest Place
Time limit1.5sMemory limit1024 MB
On a weighted undirected graph, find the vertex whose distance to the nearest of three given friends is largest, breaking ties by smallest index.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Heap, BFS
- Solved
- No attempts yet
Problem
You are looking for a house to live in, choosing one of pieces of land. Three friends , , and have houses, and you want to find the place farthest from where these friends live.
The farthest place is the one that maximizes the distance to the nearest friend's house, measured from the house you choose.
For example, suppose the distances from a house at position to the houses of friends , , and are 3, 5, and 4, and the distances from a house at position to the houses of friends , , and are 5, 7, and 2.
Then, of lands and , the one farther from the friends' houses is land . The distance from to the nearest friend's house is 3, while from it is 2.
Find the place farthest from the friends' houses.
Input
The first line gives the number of candidate pieces of land.
The second line gives the positions where friends , , and live, separated by spaces. Each friend is guaranteed to live on one of the pieces of land. (They may live at the same position.)
The third line gives the number of roads connecting pieces of land.
From the next line through line , land , land , and the length of the road connecting land and land are given, separated by spaces. This road allows two-way travel.
Output
Print the number of the land farthest from the friends' houses. If several lands are tied for farthest, print the land with the smallest number.
Constraints
- is an integer
- The lands are numbered through , one number each.
- Any two pieces of land are reachable from each other by road.