#K39107. Maximum Goods Transportation

    ID: 26347 Type: Default 1000ms 256MiB

Maximum Goods Transportation

Maximum Goods Transportation

You are given a network of stations connected by bidirectional trade routes. Each route between two stations u and v has a capacity c which indicates the maximum amount of goods that can be transported along that route. The network is structured such that there are exactly N - 1 routes connecting N stations, forming a tree.

Starting from the central station (station 1), determine the maximum amount of goods that can be transported from the central station to all other stations without exceeding any route capacities. In other words, for each station i (where i=2,3,...,N), let f(i) be the maximum goods that can be carried on a path from station 1 to station i, where for a given path the throughput is \(\min\{c_1,c_2,\dots,c_k\}\) (i.e. the minimum edge capacity along the path). Your task is to find and output the value:

\[ \min_{2 \le i \le N} f(i) \]

This represents the maximum load that can be simultaneously delivered to every station when considering the bottleneck along their respective best paths.

inputFormat

The input is given from stdin as follows:

  1. An integer N (2 ≤ N ≤ ... ) representing the number of stations.
  2. N-1 lines follow, each containing three integers u v c. Here, u and v are the station numbers connected by a trade route and c is the capacity of that route.

You may assume that the provided network forms a tree (i.e. it is connected and has no cycles).

outputFormat

Output a single integer to stdout which is the maximum amount of goods that can be delivered from station 1 to all other stations without exceeding the capacity of any trade route.

## sample
4
1 2 5
1 3 10
3 4 4
4