Xiao Ming

TimeLimit:3000MS  MemoryLimit:128MB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

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?

说出来你可能不信,这题还是没有翻译

Input

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))

Output

For each inquiry, if Xiao Ming can achieve his purpose, then output a line of "YES". Otherwise output "NO". (quotes are not output)

SampleInput
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
SampleOutput
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. 

Submit
题目统计信息详细
总AC数8
通过人数4
尝试人数8
总提交量99
AC率4.04%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: