Tree With One Edge
시간 제한1초메모리 제한1024 MB
루트 트리에서 앨리스가 한 번만 쓸 수 있는 유향 간선 (u,v)를 하나 추가할 때, 토큰을 리프로 내려보내는 게임에서 앨리스가 이기는 쌍의 수를 센다.
문제
Alice and Bob are playing a game on a tree rooted at node 1. A token is placed on the root then the players take turns making moves with Alice moving first. During a move a player must move the token from the node its on to one of that node's children. If there are no legal moves available, then the player whose turn it is will lose.
Since Alice and Bob are too good at this game they decided to play a modified version of the game. Before the game begins, Alice can add a single directed edge to the tree. Then, during the game, if the token is on vertex and the extra edge is present, the current player can choose to move the token to vertex and delete the extra edge (preventing it from being used multiple times in one game).
Of the possible pairs Alice can choose, how many will allow Alice to win the game assuming both players play optimally? Note that is allowed, as are pairs that match an existing edge in the tree (in either direction).
입력
The first line of the input contains a single integer () --- the number of test cases.
The first line of each test case contains a single integer () --- the number of vertices in the tree.
The next line of each test case contains integers () --- the parents of each vertex in the tree, except the root.
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, print a single integer --- the number of pairs that will allow Alice to win, assuming both players play optimally.
힌트
For the first test test case, here are the edges Alice can add to give herself the winning strategy:
