QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#7320. 素な木

Statistics

Bobo は根付き木に対する乗算を提案しました。

$A$ と $B$ を任意の二つの根付き木とします。$T=A\cdot B$ は、各頂点 $x\in A$ に対して $B$ のコピーを作り、そのコピーの根を $x$ と同一視することで構成されます(詳しくは次の図を参照してください)。このとき、$A$ と $B$ を $T$ の因子と呼びます。

problem_7320_6efc0a1f99681b8df5446888c2eae3c2.png

明らかに、$T\cdot1=1\cdot T=T$ が成り立ちます。ここで $1$ は頂点が一つだけの根付き木です。したがって、$1$ はすべての根付き木の因子であり、すべての根付き木はそれ自身の因子です。根付き木 $T$ の因子が $T$ と $1$ だけであるとき、$T$ を素な木と呼びます。

Bobo は、頂点に $1,2,\ldots,n$ のラベルが付いた、$n$ 頂点の根付き木 $T$ を持っています。彼は $T$ を、できるだけ多くの素な木の積に分解したいと考えています(つまり、$T=T_1\cdot T_2\cdots T_m$ という等式で、$T_i$($1\le i\le m$)が素な木であり、$m$ が最大となるものを求めます)。

$1$ は素な木ではないことに注意してください。

入力

入力には 0 個以上のテストケースが含まれ、ファイルの終端で終了します。各テストケースは次の形式です。

最初の行には、頂点数を表す整数 $n$($2\le n\le10^6$)が与えられます。

2 行目には $n-1$ 個の整数 $p_2,p_3,\ldots,p_n$ が与えられます。$p_i$ は頂点 $i$ の親です($1\le p_i\le i-1$)。

すべての $n$ の合計は $10^6$ を超えないことが保証されます。

出力

各テストケースについて、素因子の個数の最大値を表す整数を出力してください。

入出力例

入力 1

12
1 1 1 1 2 2 4 5 5 6 10
3
1 1
6
1 1 1 2 3
13
1 1 1 2 2 3 3 4 5 6 7 8

出力 1

3
1
2
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.