League of Overwatch at Moloco (Hard)
Time limit2sMemory limit512 MB
Given n employees and m conflict pairs, decide whether the employees can be split into two non-empty groups so that no pair shares a group.
- Level
Medium4 of 10
- Topics
- Graph, DFS, Union-find
- Solved
- No attempts yet
Problem
Every so often the employees of Moloco split into two groups and play a best-of-five series of League of Overwatch. Some pairs of employees are hardcore gamers who queued together as a duo in the past, so the company puts every such pair on opposite sides. The event stays enjoyable for newcomers only when it is not that competitive.
Moloco has employees, numbered 1 through .
There are known pairs of employees who played a duo game together in the past. The two employees of a pair must belong to different groups at this event.
Decide whether the employees can be split into two non-empty groups so that every employee belongs to exactly one group and no pair has both of its employees in the same group.
Input
The first line contains two integers and separated by a space (, ).
The -th of the next lines contains two integers and (). It is guaranteed that for every . The same pair is given more than once in some inputs.
Output
Print one line containing POSSIBLE if such a split exists, and IMPOSSIBLE otherwise.
Hint
In the second example, the split {2} and {1, 3} satisfies every condition.