#K43652. Team Building Groups
Team Building Groups
Team Building Groups
You are given n employees and a set of friendship pairs. Each friendship pair indicates that the two employees must be in the same group. In addition, you are provided with an integer max_size which denotes the maximum allowable number of employees in any group.
Your task is to determine the group sizes based on the friendship relations. Specifically, if any connected component (group) exceeds the allowed max_size, then the grouping is considered impossible and you should output -1. Otherwise, output the sizes of the groups in the order they are discovered using a breadth-first search starting from employee 1 to n.
The friendships implicitly form an undirected graph, and each connected component in this graph corresponds to a group.
inputFormat
The input is given via standard input (stdin).
The first line contains two integers n and max_size where 2 ≤ n ≤ 100 and 2 ≤ max_size ≤ n.
The second line contains an integer m representing the number of friendship pairs (0 ≤ m ≤ n*(n-1)/2).
Each of the following m lines contains two integers u and v (1-indexed) which indicate that employee u and employee v are friends and must be in the same group.
outputFormat
Output to standard output (stdout) a single line. If a valid grouping is possible, print the sizes of the groups separated by a single space in the order they are discovered. If no valid grouping exists (i.e., at least one group has more employees than max_size), print -1.## sample
5 3
3
1 2
3 4
4 5
2 3