#K74957. Minimal Bridge Weight
Minimal Bridge Weight
Minimal Bridge Weight
You are given an undirected weighted graph with \(n\) nodes and \(m\) edges. Each edge is described by three integers \(u\), \(v\), and \(w\), which indicate an edge between node \(u\) and node \(v\) with weight \(w\). Your task is to determine the minimal possible weight for a new bridge such that it is strictly greater than any existing edge weight, ensuring connectivity among all nodes.
In mathematical terms, if the maximum edge weight is \(\max_{1\leq i\leq m} w_i\), then the minimal possible weight for the new bridge is:
[ \text{Minimal Bridge Weight} = \max_{1\leq i\leq m} w_i + 1 ]
Design a program that reads the graph from standard input and outputs the minimal new bridge weight to standard output.
inputFormat
The input consists of multiple lines:
- The first line contains two integers \(n\) and \(m\): the number of nodes and edges, respectively.
- Each of the next \(m\) lines contains three integers \(u\), \(v\), and \(w\), representing an edge between nodes \(u\) and \(v\) with weight \(w\).
Input is provided via standard input.
outputFormat
Output a single integer --- the minimal possible weight for the new bridge, which is greater than any edge in the graph.
Output should be written to standard output.
## sample4 4
1 2 1
2 3 2
3 4 3
1 3 4
5