#K14896. Maximum Magical Power in a Tree

    ID: 24236 Type: Default 1000ms 256MiB

Maximum Magical Power in a Tree

Maximum Magical Power in a Tree

In this problem, you are given a tree with n branches and m paths. Each path connects two branches and has an associated magical power level p. Your task is to determine the maximum magical power level among all the given paths. Formally, if the power levels of the m paths are (p_1, p_2, \dots, p_m), you need to compute

[ \max_{i=1}^{m} p_i ]

If there are no paths (i.e., m = 0), then the maximum magical power is defined to be 0.

Note that the tree may be disconnected if no paths exist.

inputFormat

The input is read from standard input. The first line contains two integers n and m, where n is the number of branches and m is the number of paths. Each of the following m lines contains three integers u, v, and p, indicating that there is a path between branch u and branch v with magical power level p.

outputFormat

Output a single integer on standard output: the maximum magical power level that can be obtained among all the given paths. If there are no paths, output 0.## sample

7 6
1 2 5
2 3 6
2 4 3
3 5 4
4 6 2
4 7 8
8

</p>