- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
- I’m sorry madam, but your son is abnormal.
- (She cries out loud) but why?
- He has a strange habit of storing a rooted tree, in a simple array.
- OMG!!! How did this happen to us? What should we do now?
- Well, you should find him a problem-solver. Maybe you can find one in newbies contest!!
mrm_196 always rewrites the rooted trees in a simple array, but the array holds four conditions:
- If the tree has vertices, the array has length .
- Each vertex has a number (from to ) which is written twice (but they may not be necessarily beside each other).
- Between the numbers of each vertex, the numbers in its subtree are written.
- Vertex 1 is always the root of the tree.
For example, he may store the following tree in one of these six ways:
Your task is pretty simple, find what he always wanted, THE DEGREE OF THE TREE!!!! Degree of a tree is the maximum degree of all its vertices.
ورودی
The first line of the input contains an integer — the number tests to answer.
The first line of each test contains an integer — the number of vertices in the tree.
The second line of each test contains integers — the elements of his array.
It’s guaranteed that the given array always forms at least one valid tree.
خروجی
For each test, print a single integer in one line — the degree of the tree.
مثالها
ورودی نمونه ۱
خروجی نمونه ۱
ارسال پاسخ برای این سؤال