A9651 | An easy problem about trees
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Pieguy and Piegirl are playing a game. They have a rooted binary tree, that has a property that each node is either a leaf or has exactly two children. Each leaf has a number associated with it.
On his/her turn a player can choose any two leafs that share their immediate parent, remove them, and associate either of their values with their parent, that now became a leaf (the player decides which of the two values to associate). The game ends when only one node (the one that was the root of the tree) is left.
Pieguy goes first, and his goal is to maximize the value that will be associated with the root when the game ends. Piegirl wants to minimize that value. Assuming that both players are playing optimally, what number will be associated with the root when the game ends?
On his/her turn a player can choose any two leafs that share their immediate parent, remove them, and associate either of their values with their parent, that now became a leaf (the player decides which of the two values to associate). The game ends when only one node (the one that was the root of the tree) is left.
Pieguy goes first, and his goal is to maximize the value that will be associated with the root when the game ends. Piegirl wants to minimize that value. Assuming that both players are playing optimally, what number will be associated with the root when the game ends?
输入格式
First line contains a single integer $t$ ( $1<=t<=100$ ) — number of test cases. Then $t$ test cases follow. Each test case begins with an empty line, followed by a line with a single integer $n$ ( $1<=n<=250$ ), followed by $n$ lines describing $n$ nodes of the tree. Each of those $n$ lines either contains a non-negative number $a_{i}$ , indicating a leaf node with value $a_{i}$ ( $0<=a_{i}<=1000$ ) associated with it, or $-1$ followed by integers $l$ and $r$ , indicating a non-leaf node with children $l$ and $r$ ( $0<=l,r<=n-1$ ). Nodes are numbered from $0$ to $n-1$ . The root is always node $0$ .
输出格式
For each test case print one line with one integer on it — the number that will be associated with the root when the game ends.
输入输出样例
输入 #1
4 3 -1 1 2 10 5 5 -1 1 2 -1 3 4 10 5 20 7 -1 1 2 -1 3 4 -1 5 6 1 2 3 4 11 -1 1 2 -1 3 4 -1 5 6 -1 7 8 15 7 -1 9 10 7 8 9 11
输出 #1
10 10 4 8
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted