[Solution] Departments (Easy Version) CodeChef Solution
Problem
This is the easy version of the problem. The only difference between the easy and hard versions is that, in the easy one, additionally, there exists a solution with at least employees in every department.
ChefCorp has employees. Each employee belongs to exactly one of the departments. Each department is headed by exactly one of the employees belonging to that department.
The management structure of ChefCorp is as follows:
- Each employee of a department (including its head) is in contact with every other employee of that department.
- The head of each department is in contact with the heads of all the other departments.
For example, let , and employees belong to the first department, employees belong to the second department and employees belong to the third department (employees in bold represent the heads of the departments). The following pairs of employees are in contact with each other: .
However, due to some inexplicable reasons, ChefCorp loses all its data on the departments. Given the total number of employees and every pair of employees who are in contact with each other, can you help recover the number of
departments and the employees belonging to each of the departments?
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer — the total number of employees in ChefCorp.
- The second line of each test case contains a single integer — the number of pairs of employees in contact with each other.
- lines follow. The of these lines contain two space-separated integers and , denoting that employee is in contact with .
Output Format
- For each test case, output the following:
- In the first line output — the number of departments.
- In the second line, output space-separated integers — denoting that the employee belongs to the department.
- In the third line, output space-separated integers when — denoting that the employee is the head of the department.
If there are multiple answers, output any. It is guaranteed that at least one solution always exists.
No comments:
Post a Comment