During the summer vacation, Xiao Ming plans to travel to a place where there are n islands, each island has a bridge to another island, so there will be n bridges in total, and these bridges are two-way intercommunication. There is a bridge between the island u and the island v, which means that you can reach the island v from the island u through the bridge, and you can reach the island u from the island v through the bridge (island can only be reached by bridges)
Xiao Ming wants to achieve a goal as follows:
1. Xiao Ming want to visited all the n islands.
2. Xiao Ming wants to visit only one island twice, the other is once
Xiao Ming can choose an island to start the tour. He will leave the island after visiting the island and will not visit an island twice continuously.
Unfortunately, if Xiao Ming visits all the islands, it means that Xiaoming’s tour is over and he can no longer go to any island.
The clumsy Xiao Ming does not know if he can achieve this goal, so I would like to ask you to help answer, can you help him?
说出来你可能不信,这题还是没有翻译
A positive integer t in the first line to indicate the number of queries. (1<=t<=20)
For each case:
First line An integer n of indicates that there are n islands in the place. (2 < n <=1e5(100000))
The next line is n integers, and the i-th number vi represents a bridge between the island of i and the island of vi. (1<=vi<=n)
Ensure that vi != i, guarantee that there is no case of vi == j and vj == i (1<=i,j<=n).
(guarantee all queries ∑n<=1e5(100000))
For each inquiry, if Xiao Ming can achieve his purpose, then output a line of "YES". Otherwise output "NO". (quotes are not output)
4 4 2 3 4 1 7 2 3 1 1 1 2 2 6 2 3 1 5 6 4 8 2 3 4 1 1 5 4 4
YES NO NO YES HINT For the first example, Xiao Ming can visit 1->2->1->4->3, of which only one island has been visited twice.