CF1228F.One Node is Gone

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an integer nn. Let's define following tree generation as McDic's generation:

  1. Make a complete and full binary tree of 2n−12^{n} - 1 vertices. Complete and full binary tree means a tree that exactly one vertex is a root, all leaves have the same depth (distance from the root), and all non-leaf nodes have exactly two child nodes.
  2. Select a non-root vertex vv from that binary tree.
  3. Remove vv from tree and make new edges between vv's parent and vv's direct children. If vv has no children, then no new edges will be made.

You have a tree. Determine if this tree can be made by McDic's generation. If yes, then find the parent vertex of removed vertex in tree.

你有一个整数 nn。我们定义如下树的生成过程为 McDic 生成法:

  1. 构造一棵包含 2n−12^{n} - 1 个顶点的完全满二叉树(complete and full binary tree)。所谓完全满二叉树,是指:恰有一个顶点为根节点;所有叶子节点具有相同的深度(即到根节点的距离);所有非叶子节点均恰好有两个子节点。
  2. 从该二叉树中选取一个非根顶点 vv。
  3. 将 vv 从树中移除,并在 vv 的父节点与 vv 的直接子节点之间新建边。若 vv 没有子节点,则不添加任何新边。

你得到一棵树。请判断该树是否可通过 McDic 生成法得到。若可以,请找出被移除顶点在原树中的父节点。

输入格式

The first line contains integer nn (2≤n≤172 \le n \le 17).

The ii-th of the next 2n−32^{n} - 3 lines contains two integers aia_{i} and bib_{i} (1≤ai<bi≤2n−21 \le a_{i} \lt b_{i} \le 2^{n} - 2) — meaning there is an edge between aia_{i} and bib_{i}. It is guaranteed that the given edges form a tree.

第一行包含一个整数 nn(2≤n≤172 \le n \le 17)。

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

输出格式

Print two lines.

In the first line, print a single integer — the number of answers. If given tree cannot be made by McDic's generation, then print 00.

In the second line, print all possible answers in ascending order, separated by spaces. If the given tree cannot be made by McDic's generation, then don't print anything.

输出两行。

第一行,输出一个整数——答案的个数。如果给定的树无法由 McDic 的生成方法得到,则输出 00。

第二行,按升序输出所有可能的答案,各答案之间用空格分隔。如果给定的树无法由 McDic 的生成方法得到,则第二行不输出任何内容。

输入输出样例

  • 输入#1

    4
    1 2
    1 3
    2 4
    2 5
    3 6
    3 13
    3 14
    4 7
    4 8
    5 9
    5 10
    6 11
    6 12

    输出#1

    1
    3
  • 输入#2

    2
    1 2

    输出#2

    2
    1 2
  • 输入#3

    3
    1 2
    2 3
    3 4
    4 5
    5 6

    输出#3

    0

说明/提示

In the first example, 33 is the only possible answer.

In the second example, there are 22 possible answers.

In the third example, the tree can't be generated by McDic's generation.

在第一个例子中,33 是唯一的可能答案。

在第二个例子中,有 22 个可能的答案。

在第三个例子中,该树无法由 McDic 的生成方法产生。

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

首页