#K64587. Maximum Edge Weight in Tree Paths

    ID: 32008 Type: Default 1000ms 256MiB

Maximum Edge Weight in Tree Paths

Maximum Edge Weight in Tree Paths

Given a tree with (n) nodes and (n-1) weighted undirected edges, your task is to determine the maximum edge weight encountered on the unique path from the root (node 1) to any of the other nodes. The tree is connected, so every edge lies on the unique path between node 1 and some other node.

For example, if the tree has 5 nodes and the edges are given as:
1 2 4
1 3 3
2 4 2
2 5 6
Then the output should be 6 because the edge with weight 6 is the heaviest encountered from the root.

All formulas are provided in (\LaTeX) format.

inputFormat

Input is given via standard input (stdin).

The first line contains an integer (n), the number of nodes in the tree. Each of the next (n-1) lines contains three space-separated integers (u), (v), and (w), indicating that there is an edge between nodes (u) and (v) with a weight of (w).

outputFormat

Output a single integer to standard output (stdout) representing the maximum edge weight along any path from node 1 to any other node.## sample

5
1 2 4
1 3 3
2 4 2
2 5 6
6