A12909 | One Node is Gone
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have an integer $n$ . Let's define following tree generation as McDic's generation:
1. Make a complete and full binary tree of $2^{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 $v$ from that binary tree.
3. Remove $v$ from tree and make new edges between $v$ 's parent and $v$ 's direct children. If $v$ 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.
1. Make a complete and full binary tree of $2^{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 $v$ from that binary tree.
3. Remove $v$ from tree and make new edges between $v$ 's parent and $v$ 's direct children. If $v$ 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.
输入格式
The first line contains integer $n$ ( $2 \le n \le 17$ ).
The $i$ -th of the next $2^{n} - 3$ lines contains two integers $a_{i}$ and $b_{i}$ ( $1 \le a_{i} \lt b_{i} \le 2^{n} - 2$ ) — meaning there is an edge between $a_{i}$ and $b_{i}$ . It is guaranteed that the given edges form a tree.
The $i$ -th of the next $2^{n} - 3$ lines contains two integers $a_{i}$ and $b_{i}$ ( $1 \le a_{i} \lt b_{i} \le 2^{n} - 2$ ) — meaning there is an edge between $a_{i}$ and $b_{i}$ . It is guaranteed that the given edges form a tree.
输出格式
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 $0$ .
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.
In the first line, print a single integer — the number of answers. If given tree cannot be made by McDic's generation, then print $0$ .
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.
输入输出样例
输入 #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, $3$ is the only possible answer.
In the second example, there are $2$ possible answers.
In the third example, the tree can't be generated by McDic's generation.
In the second example, there are $2$ possible answers.
In the third example, the tree can't be generated by McDic's generation.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted