A group of perfect logicians has again received a request to be the main protagonists
of a new logic puzzle. They must now agree upon which
This time the logic puzzle takes place on an undirected graph with
They already suspected that the catch might be related to their eye colour, so they decided to arrange themselves so that each logician sees exactly one other person with blue eyes. As it usually happens to be, none of the logicians can see their own eye colour, which means that even logicians with blue eyes should see exactly one other person with blue eyes.
What is the least number of blue-eyed logicians needed to make the required arrangement?
Constraints
In every subtask, it holds that
Subtask | Points | Constraints |
---|---|---|
1 | 10 | Each logician sees exactly two other logicians. |
2 | 10 | |
3 | 40 | |
4 | 50 | No additional constraints. |
Input Specification
The first line contains the integer
The following
Output Specification
If the required arrangement does not exist, in the first and only line output -1
.
Otherwise, in the first and only line output the required least number of blue-eyed logicians.
Sample Input 1
4
1 2
2 3
3 4
4 1
Sample Output 1
2
Explanation for Sample Output 1
Blue-eyed logicians could for example be those on nodes
Sample Input 2
3
1 2
2 3
3 1
Sample Output 2
-1
Explanation for Sample Output 2
If only one of the logicians has blue eyes, then he surely can't see anyone else with blue eyes. If there are two or more of them with blue eyes, then surely someone will see more than one person with blue eyes.
Sample Input 3
7
1 2
2 3
3 4
4 5
5 6
6 7
2 4
Sample Output 3
4
Comments