#K6186. Optimal Capital
Optimal Capital
Optimal Capital
In a kingdom far away, there are n provinces connected by bidirectional roads forming a tree. The king wishes to choose a province as the new capital such that the maximum distance from the capital to any other province is minimized. In other words, if the distance from a candidate capital to the farthest province is as small as possible, that candidate is considered optimal. If there are multiple optimal capitals, the one with the smallest numerical index should be chosen.
The road network is given as a list of roads where each road is described by three integers u
, v
, and w
, representing that there is a bidirectional road between provinces u
and v
with length w
. It is guaranteed that the network is connected.
Your task is to determine the optimal capital province.
inputFormat
The input is read from standard input (stdin). The first line contains two integers n
and m
, where n
is the number of provinces and m
is the number of roads. Each of the next m
lines contains three integers u
, v
, and w
, representing a bidirectional road between provinces u
and v
with length w
.
outputFormat
Output a single integer on stdout, which is the province number that should be chosen as the capital.## sample
3 2
1 2 3
2 3 4
2