Meeting
Time limit1sMemory limit1024 MB
Given a bipartite like-graph between N men and N women, find a subset of men whose neighborhood (women liking at least one chosen man) is strictly smaller than the subset size, or report that no such subset exists.
- Level
Medium7 of 10
- Topics
- Graph, Union-find, Greedy, Implementation
- Solved
- No attempts yet
Problem

There are men and women who signed up for a meeting arranged by Gukryeol, hoping to meet a romantic partner.
We are given pairs of a man and a woman who like each other. Gukryeol wants to run the meeting by picking an arbitrary subset of the men who signed up. Seeing the men he picked, every woman who likes at least one of them joins the meeting. If the number of men at the meeting is less than or equal to the number of women, the meeting goes smoothly. If instead there are more men, the meeting cannot go smoothly. In the example in the figure, when the 2nd man and the 3rd man are picked, the only woman who likes either of them is the 2nd woman, and since there are more men, the meeting cannot go smoothly.
Gukryeol is the one arranging this meeting, but he comes from an undefeated singles squad and does not want others to do well, so he wants to prevent the meeting from going smoothly. Given the like relationships between men and women, pick the men so that the meeting does not go smoothly.
Input
The first line gives and . (, )
The next lines each give two integers and . This means the -th man and the -th woman like each other. Each man-woman relationship is given at most once.
Output
If you can pick men so that the meeting cannot go smoothly, print the number of men to pick on the first line. On the next line, print the indices of the men to pick. If there are several valid ways, print any of them.
If the meeting can go smoothly no matter how the men are picked, print -1 on the first line.