Cut 'em all!

TimeLimit:1000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

You're given a tree with  vertices.

Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.


Input

The first line contains an integer n () denoting the size of the tree.

The next  lines contain two integers uv () each, describing the vertices connected by the i-th edge.

It's guaranteed that the given edges form a tree.


Output

Output a single integer  — the maximum number of edges that can be removed to leave all connected components with even size, or 1 if it is impossible to remove edges in order to satisfy this property.

SampleInput 1
4
2 4
4 1
3 1
SampleOutput 1
1
SampleInput 2
3
1 2
1 3
SampleOutput 2
-1
SampleInput 3
10
7 1
8 4
8 10
4 7
6 5
9 3
3 5
2 10
2 5
SampleOutput 3
4
SampleInput 4
2
1 2
SampleOutput 4
0
Note

In the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each.

In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.

Submit
题目统计信息详细
总AC数1
通过人数1
尝试人数1
总提交量1
AC率100.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: