#K84212. Heidi's Pathway Reinforcement
Heidi's Pathway Reinforcement
Heidi's Pathway Reinforcement
Heidi is tasked with securing a series of historic sites connected by ancient pathways. Each pathway has a unique width, and the goal is to determine the maximum width that any pathway not used in the primary reinforcement plan (the Minimum Spanning Tree, or MST) can handle without disrupting the network’s flow.
Given n sites and m pathways, you are to construct the MST of the network. Let \(W_{max}\) denote the maximum edge weight in the MST. For every pathway that is not part of the MST, compute \(W_{max}(p) = \max(w_p, W_{max})\), where \(w_p\) is the width of that pathway.
Constraints:
- \(2 \leq n \leq 5000\)
- \(n-1 \leq m \leq 20000\)
- Pathway widths are distinct and satisfy \(1 \leq w \leq 1000\)
- The network is guaranteed to be connected.
Example:
Input: 4 5 1 2 5 2 3 7 3 4 6 1 3 4 2 4 8</p>Output: 7 8
inputFormat
The first line contains two integers n and m separated by a space, representing the number of sites and the number of pathways respectively.
Then m lines follow. Each line contains three integers x, y, and w, where x and y are the two sites connected by a pathway, and w is the distinct width of that pathway.
It is guaranteed that the network is connected and that no pair of sites is repeated.
outputFormat
Output the computed values for each pathway that is not part of the MST. For each such pathway, output \(W_{max}(p)\) (i.e. \(\max(w_p, W_{max})\)) in the same order as the input appears (only considering non-MST pathways). The outputs should be printed on a single line separated by a space. If there are no such pathways, output an empty line.
## sample4 5
1 2 5
2 3 7
3 4 6
1 3 4
2 4 8
7 8