#C5530. Forest Connectivity Challenge
Forest Connectivity Challenge
Forest Connectivity Challenge
You are given a forest with (n) trees (numbered from 1 to (n)) and a maximum number (m) of paths allowed to connect them. A path connects two consecutive trees (i.e., tree (i) and tree (i+1)). Your task is to determine if it is possible to connect all trees (i.e., the forest is connected) under the constraint that you can use at most (m) paths. Note that the minimum number of paths required to connect (n) trees is (n-1) (i.e., (m \ge n-1)).
If it is possible, output "Yes" on the first line followed by (n-1) lines each containing two space-separated integers representing the connected trees. Otherwise, output "No".
The solution must read input from stdin and print the answer to stdout.
inputFormat
The input consists of a single line containing two space-separated integers: (n) (the number of trees) and (m) (the maximum number of paths allowed).
outputFormat
If it is possible to connect all (n) trees, print "Yes" on the first line, and then print (n-1) lines, each containing two space-separated integers representing an edge between trees. If it is not possible, print "No".## sample
5 10
Yes
1 2
2 3
3 4
4 5
</p>