This page is still under construction.

Parts of this page are still being built. What you see may change.

Farthest Place

Time limit1.5sMemory limit1024 MB

Summary
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 NN pieces of land. Three friends AA, BB, and CC 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 XX to the houses of friends AA, BB, and CC are 3, 5, and 4, and the distances from a house at position YY to the houses of friends AA, BB, and CC are 5, 7, and 2.

Then, of lands XX and YY, the one farther from the friends' houses is land XX. The distance from XX to the nearest friend's house is 3, while from YY it is 2.

Find the place farthest from the friends' houses.

Input

The first line gives the number NN of candidate pieces of land.

The second line gives the positions where friends AA, BB, and CC live, separated by spaces. Each friend is guaranteed to live on one of the NN pieces of land. (They may live at the same position.)

The third line gives the number MM of roads connecting pieces of land.

From the next line through line M+3M + 3, land DD, land EE, and the length LL of the road connecting land DD and land EE 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

  • 1≤N≤100,0001 \le N \le 100,000
  • N−1≤M≤500,000N - 1 \le M \le 500,000
  • 1≤A,B,C,D,E≤N1 \le A, B, C, D, E \le N
  • 1≤L≤10,0001 \le L \le 10,000
  • LL is an integer
  • The lands are numbered 11 through NN, one number each.
  • Any two pieces of land are reachable from each other by road.

Examples1

  1. Example 1

    Input
    6
    1 2 5
    8
    1 2 1
    2 3 4
    1 4 2
    2 5 3
    1 6 5
    5 6 2
    3 4 2
    4 5 6
    
    Expected output
    3