CF982C.Cut 'em all!

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You're given a tree with nn 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.
给你一棵有 nn 个顶点的树。

你的任务是确定可以移除的最大边数,从而使所有剩余的连接部分大小相同。

输入格式

The first line contains an integer nn ( 1n1051 \le n \le 10^5 ) denoting the size of the tree.

The next n1n - 1 lines contain two integers uu , vv ( 1u,vn1 \le u, v \le n ) each, describing the vertices connected by the ii -th edge.

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

第一行包含一个整数 nn ( 1n1051 \le n \le 10^5 ),表示树的大小。

接下来的 n1n - 1 行分别包含两个整数 uuvv ( 1u,vn1 \le u, v \le n ),描述由 ii -th 边连接的顶点。

可以保证给定的边构成一棵树。

输出格式

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

输出单个整数 kk - 为使所有相连的组件大小相同而可以去除的最大边数,或者 1-1 - 如果无法去除边以满足此属性。

输入输出样例

  • 输入#1

    4
    2 4
    4 1
    3 1
    

    输出#1

    1
  • 输入#2

    3
    1 2
    1 3
    

    输出#2

    -1
  • 输入#3

    10
    7 1
    8 4
    8 10
    4 7
    6 5
    9 3
    3 5
    2 10
    2 5
    

    输出#3

    4
  • 输入#4

    2
    1 2
    

    输出#4

    0

说明/提示

In the first example you can remove the edge between vertices 11 and 44 . 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-1 .
备注

在第一个示例中,您可以删除顶点 1144 之间的边。之后的图形将有两个相连的部分,每个部分有两个顶点。

在第二个示例中,无法通过删除边的方式使所有分量的顶点数都是偶数,因此答案是 1-1

首页