#C9052. Minimum Maximum Edge in a Minimum Spanning Tree

    ID: 53103 Type: Default 1000ms 256MiB

Minimum Maximum Edge in a Minimum Spanning Tree

Minimum Maximum Edge in a Minimum Spanning Tree

Given an undirected weighted graph with (n) nodes and (m) edges, your task is to compute a minimum spanning tree (MST) and then determine the minimum possible value of the maximum edge weight in any MST. In other words, among all MSTs of the graph, find one whose largest edge weight is as small as possible. Formally, if an MST contains (n-1) edges with weights (w_1, w_2, \ldots, w_{n-1}), you should output the value of (\max{w_1, w_2, \ldots, w_{n-1}}).

Note: The graph is given in the form of edges where each edge is represented by three integers (u), (v) and (w) indicating that there is an edge between nodes (u) and (v) with weight (w). It is guaranteed that the graph is connected, so at least one MST exists.

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains two integers (n) and (m) representing the number of nodes and edges respectively.
Each of the following (m) lines contains three space-separated integers (u), (v), and (w), describing an edge between node (u) and node (v) with weight (w).

outputFormat

Output a single integer to standard output (stdout) — the minimum possible value of the maximum edge weight in a minimum spanning tree of the given graph.## sample

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