mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-30 00:37:37 +08:00
44 lines
1.2 KiB
HTML
44 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1110. Complete Binary Tree (25)</h1>
|
|
<div id="problemContent">
|
|
<p>Given a tree, you are supposed to tell if it is a complete binary tree.</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>Each input file contains one test case. For each case, the first line gives a positive integer N (<=20) which is the total number of nodes in the tree -- and hence the nodes are numbered from 0 to N-1. Then N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a "-" will be put at the position. Any pair of children are separated by a space.</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each case, print in one line "YES" and the index of the last node if the tree is a complete binary tree, or "NO" and the index of the root if not. There must be exactly one space separating the word and the number.
|
|
</p>
|
|
<b>Sample Input 1:</b><pre>
|
|
9
|
|
7 8
|
|
- -
|
|
- -
|
|
- -
|
|
0 1
|
|
2 3
|
|
4 5
|
|
- -
|
|
- -
|
|
</pre>
|
|
<b>Sample Output 1:</b><pre>
|
|
YES 8
|
|
</pre>
|
|
<b>Sample Input 2:</b><pre>
|
|
8
|
|
- -
|
|
4 5
|
|
0 6
|
|
- -
|
|
2 3
|
|
- 7
|
|
- -
|
|
- -
|
|
</pre>
|
|
<b>Sample Output 2:</b><pre>
|
|
NO 1
|
|
</pre>
|
|
</div> |