Logo
(追記) (追記ここまで)

28166번 - TreeScript 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB58373168.889%

문제

TreeScript is a programming language developed for maintaining tree structures. In this problem, we will learn how to create rooted trees in TreeScript.

In TreeScript, all tree nodes are stored in memory. Each tree node has a number and the address of its parent node, and both are immutable, so they have to be determined when creating the node. In particular, the address of the root node's parent node is empty.

In order to access these nodes, the address of a node can be stored in a register. If there are $m$ registers, the registers can be written as $r[0],r[1],\ldots ,r[m-1]$.

Now let's learn the node creation statement: $$r[i]=\mathrm{create}(r[j], k);$$ where $k$ is the node number, $i$ and $j$ are the indices of the registers, where 0ドル\le i,j< m$ and $i=j$ is possible. The effect of this statement is that a node numbered $k$ is created, whose parent address is stored in $r[j],ドル and then the new node's address is stored in $r[i]$. Once each node has been created correctly, you do not need to store the address of any more nodes; they will automatically execute the pre-defined instructions. For reasons of space, we will learn about them later.

To check your learning, you need to create a rooted tree of size $n$. At first, the system will automatically create the root node for you and store it in $r[0]$. So you only need to execute $n-1$ additional creation instructions to create the tree.

As you know, registers are very expensive, so you need to find the minimum amount $m$ of the registers you need.

입력

There are multiple test cases.

The first line of the input contains one integer $T$ (1ドル\le T\le 10^5$) --- the number of test cases.

For each test case:

The first line contains one integer $n$ (2ドル\le n\le 2\cdot 10^5$) --- the size of the tree.

The second line contains $n$ integers $p_1,p_2,\ldots,p_n,ドル where node $p_i$ is the parent node of node $i$ and 1ドル\le p_i<i$. Specially, $p_1=0$ and it means 1ドル$ is the root of the tree.

The sum of $n$ over all test cases does not exceed 2ドル\times 10^5$.

출력

For each test case, output the answer in one line.

제한

예제 입력 1

2
3
0 1 2
7
0 1 2 2 1 4 1

예제 출력 1

1
2

힌트

출처

ICPC > Regionals > Asia East Continent > Hong Kong > 2023 ICPC Hong Kong Regional A번

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 3: 2023 ICPC Asia Hong Kong Regional A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /