CF1338B.Edge Weight Assignment

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have unweighted tree of nn vertices. You have to assign a positive weight to each edge so that the following condition would hold:

  • For every two different leaves v1v_{1} and v2v_{2} of this tree, bitwise XOR of weights of all edges on the simple path between v1v_{1} and v2v_{2} has to be equal to 00.

Note that you can put very large positive integers (like 10(1010)10^{(10^{10})}).

It's guaranteed that such assignment always exists under given constraints. Now let's define ff as the number of distinct weights in assignment.

In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 00. ff value is 22 here, because there are 22 distinct edge weights(44 and 55).

In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 11 and vertex 66 (3,4,5,43, 4, 5, 4) is not 00.

What are the minimum and the maximum possible values of ff for the given tree? Find and print both.

你有一棵包含 nn 个顶点的无权树。你需要为每条边赋予一个正整数权重,使得以下条件成立:

  • 对于该树中任意两个不同的叶子节点 v1v_{1} 和 v2v_{2},连接 v1v_{1} 与 v2v_{2} 的简单路径上所有边的权重的**按位异或(XOR)**结果必须等于 00。

注意:你可以使用非常大的正整数(例如 10(1010)10^{(10^{10})})。

在给定约束下,保证这样的赋权方案总是存在的。现在定义 ff 为所赋边权中互不相同的权值个数。

在该示例中,赋权方案是合法的,因为任意两个叶子节点之间路径上所有边权的按位异或均为 00。此处 f=2f = 2,因为共使用了 22 种不同的边权(44 和 55)。

在该示例中,赋权方案是非法的,因为顶点 11 与顶点 66 之间路径上的边权(3,4,5,43, 4, 5, 4)的按位异或结果不为 00。

对于给定的树,ff 的最小可能值和最大可能值分别是多少?请找出并输出这两个值。

输入格式

The first line contains integer nn (3≤n≤1053 \le n \le 10^{5}) — the number of vertices in given tree.

The ii-th of the next n−1n-1 lines contains two integers aia_{i} and bib_{i} (1≤ai<bi≤n1 \le a_{i} \lt b_{i} \le n) — it means there is an edge between aia_{i} and bib_{i}. It is guaranteed that given graph forms tree of nn vertices.

第一行包含一个整数 nn(3≤n≤1053 \le n \le 10^{5})—— 表示给定树的顶点数。

接下来的 n−1n-1 行中,第 ii 行包含两个整数 aia_{i} 和 bib_{i}(1≤ai<bi≤n1 \le a_{i} \lt b_{i} \le n)—— 表示顶点 aia_{i} 与 bib_{i} 之间存在一条边。保证所给图构成一棵含有 nn 个顶点的树。

输出格式

Print two integers — the minimum and maximum possible value of ff can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.

输出两个整数——在给定树的有效赋值下,ff 可能取得的最小值和最大值。注意:在给定约束条件下,总能找到一种有效赋值。

输入输出样例

  • 输入#1

    6
    1 3
    2 3
    3 4
    4 5
    5 6

    输出#1

    1 4
  • 输入#2

    6
    1 3
    2 3
    3 4
    4 5
    4 6

    输出#2

    3 3
  • 输入#3

    7
    1 2
    2 7
    3 4
    4 7
    5 6
    6 7

    输出#3

    1 6

说明/提示

In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.

In the second example, possible assignments for each minimum and maximum are described in picture below. The ff value of valid assignment of this tree is always 33.

In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.

在第一个例子中,每个最小值和最大值的可能赋值如下图所示。当然,每个最小值和最大值都有多种可能的赋值方式。

在第二个例子中,每个最小值和最大值的可能赋值如下图所示。该树的有效赋值的 ff 值恒为 33。

在第三个例子中,每个最小值和最大值的可能赋值如下图所示。当然,每个最小值和最大值都有多种可能的赋值方式。

输入解题思路,AI测评打分。不知道怎么写?

首页