#K62422. Delivery Network Supervisors
Delivery Network Supervisors
Delivery Network Supervisors
In this problem, you are given a delivery network with N locations and M bidirectional paths connecting them. Location 1 serves as the hub. Your task is to assign a supervisor for each location (from 2 to N) using a Breadth-First Search (BFS) starting from the hub. The supervisor of a location is defined as the location from which it was first reached during the BFS. If any location is unreachable from the hub, output "No". Otherwise, output "Yes" followed by the supervisor for each location in order.
The assignment follows these rules: (\textbf{Input:})
- The first line contains two integers (N) and (M) (the number of locations and the number of paths respectively).
- Each of the next (M) lines contains two integers (A) and (B), representing a bidirectional path between locations (A) and (B). (\textbf{Output:})
- If all locations (from 2 to N) can be reached from location 1, print "Yes" followed by (N-1) lines, each containing the supervisor of location (i) for (2 \le i \le N).
- If at least one location is unreachable, print "No".
Your solution must read from standard input and write to standard output.
inputFormat
The input starts with a line containing two integers (N) and (M). This is followed by (M) lines, each containing two integers (A) and (B), indicating a bidirectional path between locations (A) and (B).
outputFormat
If every location can be reached from location 1, output "Yes" on the first line, and then output (N-1) lines where the (i)th line (for (2 \le i \le N)) contains the supervisor of location (i). If there is any location unreachable from location 1, output "No".## sample
5 5
1 2
2 3
3 4
4 5
5 2
Yes
1
2
3
2
</p>