CF1685D1.Permutation Weight (Easy Version)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an easy version of the problem. The difference between the easy and hard versions is that in this version, you can output any permutation with the smallest weight.
You are given a permutation p1,p2,…,pn of integers from 1 to n .
Let's define the weight of the permutation q1,q2,…,qn of integers from 1 to n as $$$$|q_1 - p_{q_{2}}| + |q_2 - p_{q_{3}}| + \ldots + |q_{n-1} - p_{q_{n}}| + |q_n - p_{q_{1}}| $$
You want your permutation to be as lightweight as possible. Find any permutation q$$ with the smallest possible weight.
输入格式
The first line of the input contains a single integer t ( 1≤t≤100 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤200 ) — the size of the permutation.
The second line of each test case contains n integers p1,p2,…,pn ( 1≤pi≤n , all pi are distinct) — the elements of the permutation.
The sum of n over all test cases doesn't exceed 400 .
输出格式
For each test case, output n integers q1,q2,…,qn ( 1≤qi≤n , all qi are distinct) — one of the permutations with the smallest weight.
输入输出样例
输入#1
3 2 2 1 4 2 3 1 4 5 5 4 3 2 1
输出#1
1 2 1 3 4 2 1 4 2 3 5
说明/提示
In the first test case, there are two permutations of length 2 : (1,2) and (2,1) . Permutation (1,2) has weight ∣1−p2∣+∣2−p1∣=0 , and permutation (2,1) has the same weight: ∣2−p1∣+∣1−p2∣=0 . You can output any of these permutations in this version.
In the second test case, the weight of the permutation (1,3,4,2) is ∣1−p3∣+∣3−p4∣+∣4−p2∣+∣2−p1∣=∣1−1∣+∣3−4∣+∣4−3∣+∣2−2∣=2 . There are no permutations with smaller weights.
In the third test case, the weight of the permutation (1,4,2,3,5) is ∣1−p4∣+∣4−p2∣+∣2−p3∣+∣3−p5∣+∣5−p1∣=∣1−2∣+∣4−4∣+∣2−3∣+∣3−1∣+∣5−5∣=4 . There are no permutations with smaller weights.