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$ بإنشاء نسخة من $B$ لكل رأس $x \in A$ ودمج جذر هذه النسخة مع $x$ (انظر الشكل التالي لمزيد من التفاصيل). عندئذ نسمي $A$ و$B$ عاملين للشجرة $T$.

problem_7320_2d2451421056d4dd944f143ba2a0dea5.png

من الواضح أن $T \cdot \mathbf{1} = \mathbf{1} \cdot T = T$، حيث $\mathbf{1}$ هي الشجرة ذات الجذر التي تحتوي على رأس واحد فقط. إذن، $\mathbf{1}$ عامل لكل شجرة ذات جذر، وكل شجرة ذات جذر عامل لنفسها. وإذا كانت الشجرة ذات الجذر $T$ لا تملك إلا $T$ و$\mathbf{1}$ عاملين لها، فإننا نسمي $T$ شجرة أولية.

لدى Bobo شجرة ذات جذر $T$ تحتوي على $n$ عقدة مرقمة على نحو مناسب بالأعداد $1, 2, \ldots, n$. يريد تحليل $T$ إلى حاصل ضرب أكبر عدد ممكن من الأشجار الأولية (أي إيجاد معادلة $T = T_1 \cdot T_2 \cdots T_m$، حيث تكون $T_i$ ($1 \le i \le m$) أشجارًا أولية وتكون $m$ أكبر ما يمكن).

لاحظ أن $\mathbf{1}$ ليست شجرة أولية.

الإدخال

يحتوي الإدخال على صفر أو أكثر من حالات الاختبار، وينتهي بنهاية الملف. لكل حالة اختبار:

يحتوي السطر الأول على عدد صحيح $n$، وهو عدد العقد ($2 \le n \le 10^6$).

يحتوي السطر الثاني على $(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.