The Sponsor's Cable
A sponsor insists that edge number K be part of the network. Print the minimum total cost of a spanning tree CONTAINING edge K, or IMPOSSIBLE.
Input: the first line has N, M and K; each of the next M lines has u v w (edges numbered 1..M in input order).
Output: the minimum spanning-tree weight that includes edge K, or IMPOSSIBLE.
Constraints:
- 2 ≤ N ≤ 104
- 1 ≤ M ≤ 2×104
Sample Tests
Input 1
4 5 4 1 2 1 2 3 2 3 4 1 1 4 5 1 3 2
Output 1
7
Input 2
2 1 1 1 2 3
Output 2
3
Discussion (opens after you solve — no spoilers before)
No comments yet.