eolymp
bolt
Try our new interface for solving problems

Logic

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 $n$ of them should participate. This time the logic puzzle takes place on an undirected graph with $n$ nodes, and logically, $n$ edges. Each edge connects two different nodes and between any two nodes there is at most one edge. Additionally, the graph is connected, which means that it is possible to go from any node to any other node via a sequence of edges. For each node there will be one logician located on that node and each logician is able to see precisely those logicians whose nodes are connected by an edge with their own node. They already suspected that the catch might be related to their eye color, so they decided to arrange themselves so that each logician sees exactly one other person with blue eyes. As it ususally happens to be, none of the logicians can see their own eye color, 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? \InputFile The first line contains the integer $n~(3 \le n \le 10^5)$ --- the number of nodes in the graph, and also the number of logicians. The following $n$ lines contain pairs of integers representing the edges of the graph. Each edge connects two different nodes and no edge is repeated twice in the input. \OutputFile If the required arrangement does not exist, in the first and only line output $-1$. Otherwise, print the required least number of blue-eyed logicians.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
1 2
2 3
3 4
4 1
Output example #1
2
Input example #2
3
1 2
2 3
3 1
Output example #2
-1
Input example #3
7
1 2
2 3
3 4
4 5
5 6
6 7
2 4
Output example #3
4
Source 2021 COCI Croatian Open Competition In Informatics, Round 1, October 16