F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Link with Limit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1628    Accepted Submission(s): 469


Problem Description
Link has a function $f(x)$, where $x$ and $f(x)$ are both integers in $[1,n]$.

Let $f_n(x)=f(f_{n-1}(x))$ and $f_1(x) = f(x)$, he define the power of a number $x$ as:
$$g(x) = \lim \limits_{n \to + \infty} \frac{1}{n} \sum_{i=1}^{n} f_i(x)$$

He wants to know whether $x$ has the same power for all $x \in [1,n]$.
 

Input
The input consists of multiple test cases.

The first line contains an integer $T$ ($1 \leq T \leq 100$) -- the number of test cases.

For each test case:

In the first line, there is an integer $n$ ($1 \leq n \leq 10^5$).

In the second line, there are $n$ integers, the $i$-th integer shows the value of $f(i)$ ($1 \leq f(i) \leq n$).

It is guaranteed that the sum of $n$ over all test cases will not exceed $10^6$.
 

Output
For each test case, output 'YES' if all $x$ have the same power. Otherwise, output 'NO'.
 

Sample Input
2 2 1 2 2 1 1
 

Sample Output
NO YES
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:59:30, Gzip enabled