| Contests - ACM Student Chapter - PSUT |
|---|
| Private |
| Spectator |
| PSUT Programming Contest 2026 |
|---|
| Finished |
Ayoub gave Kilani an array $$$a$$$ of length $$$n$$$, where each element satisfies $$$1 \le a_i \le n$$$. The elements of $$$a$$$ are not necessarily distinct.
He may reorder (permute) the elements of the array in any way he wants. After choosing an ordering, he constructs an undirected graph with $$$n$$$ vertices labeled $$$1$$$ to $$$n$$$, and for each index $$$i$$$, he adds an edge between vertex $$$i$$$ and vertex $$$a_i$$$.
Self-loops (when $$$i = a_i$$$) and multiple edges are allowed.
Determine whether there exists a reordering of the array such that the resulting graph is connected.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.
For each test case:
41121 244 4 4 451 2 3 4 5
Yes1Yes2 1Yes4 4 4 4Yes2 3 4 5 1
| Name |
|---|

