mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-04 00:38:13 +08:00
18 lines
3.9 KiB
HTML
18 lines
3.9 KiB
HTML
Counting Leaves
|
|
<div class="ques-view"><p>A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.</p>
|
|
<h3 id="input-specification-">Input Specification:</h3>
|
|
<p>Each input file contains one test case. Each case starts with a line containing <span class="katex"><span class="katex-mathml"><math><mrow><mn>0</mn><mo><</mo><mi>N</mi><mo><</mo><mn>1</mn><mn>0</mn><mn>0</mn></mrow>0<N<100</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.72243em;vertical-align:-0.0391em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mrel"><</span><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="mrel"><</span><span class="mord mathrm">1</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span></span></span></span>, the number of nodes in a tree, and <span class="katex"><span class="katex-mathml"><math><mrow><mi>M</mi></mrow>M</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">M</span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mo><</mo><mi>N</mi></mrow><N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.72243em;vertical-align:-0.0391em;"></span><span class="base textstyle uncramped"><span class="mrel"><</span><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span>), the number of non-leaf nodes. Then <span class="katex"><span class="katex-mathml"><math><mrow><mi>M</mi></mrow>M</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">M</span></span></span></span> lines follow, each in the format:</p>
|
|
<pre><code>ID K ID[1] ID[2] ... ID[K]
|
|
</code></pre><p>where <code>ID</code> is a two-digit number representing a given non-leaf node, <code>K</code> is the number of its children, followed by a sequence of two-digit <code>ID</code>'s of its children. For the sake of simplicity, let us fix the root ID to be <code>01</code>.</p>
|
|
<p>The input ends with <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> being 0. That case must NOT be processed.</p>
|
|
<h3 id="output-specification-">Output Specification:</h3>
|
|
<p>For each test case, you are supposed to count those family members who have no child <strong>for every seniority level</strong> starting from the root. The numbers must be printed in a line, separated by a space, and there must be no extra space at the end of each line.</p>
|
|
<p>The sample case represents a tree with only 2 nodes, where <code>01</code> is the root and <code>02</code> is its only child. Hence on the root <code>01</code> level, there is <code>0</code> leaf node; and on the next level, there is <code>1</code> leaf node. Then we should output <code>0 1</code> in a line.</p>
|
|
<h3 id="sample-input-">Sample Input:</h3>
|
|
<pre><code class="lang-in">2 1
|
|
01 1 02
|
|
</code></pre>
|
|
<h3 id="sample-output-">Sample Output:</h3>
|
|
<pre><code class="lang-out">0 1
|
|
</code></pre>
|
|
</div> |