AtCoder Grand Contest 060
E
Number of Cycles
AtCoder
⌀ 3452
原题
← DF →
翻译中…

Problem Statement

翻译中…

In this problem, a permutation of $(1,2,\cdots,N)$ is occasionally called just a permutation.

翻译中…

For a permutation $a=(a_1,a_2,\cdots,a_N)$, let $f(a)$ be the number of cycles in $a$. More accurately, the value of $f(a)$ is defined as follows.

翻译中…
  • Consider an undirected graph consisting of $N$ vertices numbered $1$ to $N$. For each $1 \leq i \leq N$, add an edge connecting vertex $i$ and vertex $a_i$. Then, let $f(a)$ be the number of connected components in this graph.
翻译中…

You are given a permutation $P=(P_1,P_2,\cdots,P_N)$ and an integer $K$. Determine whether there is a permutation $x$ that satisfies the following condition, and construct one if it exists.

翻译中…
  • Let $y_i=P_{x_i}$ to define a permutation $y$.
  • Then, $f(x)+f(y)=K$ holds.
翻译中…

For each input file, solve $T$ test cases.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 10^5$
  • $2 \leq N \leq 2 \times 10^5$
  • $2 \leq K \leq 2N$
  • $(P_1,P_2,\cdots,P_N)$ is a permutation of $(1,2,\cdots,N)$.
  • In each input file, the sum of $N$ does not exceed $2 \times 10^5$.
  • All numbers in the input are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
case_1
case_2
\vdots
case_T

翻译中…

Each case is in the following format:

翻译中…

N K
P_1 P_2 \cdots P_N

翻译中…

Output

翻译中…

For each case, if no permutation $x$ satisfies the condition, print No. Otherwise, print your answer in the following format:

翻译中…

Yes
x_1 x_2 \cdots x_N

翻译中…

Each character in Yes or No in the output may be either uppercase or lowercase. If multiple solutions exist, any of them will be accepted.

翻译中…

样例

Input #1
3
3 3
1 3 2
2 2
2 1
4 8
1 2 3 4
Output #1
Yes
2 1 3
No
Yes
1 2 3 4
In the first case, letting $x=(2,1,3)$ makes $y=(3,1,2)$, satisfying $f(x)+f(y)=2+1=3$.
题目信息
题号
agc060_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。