atcoder#AGC060E. [AGC060E] Number of Cycles
[AGC060E] Number of Cycles
Score : points
Problem Statement
In this problem, a permutation of is occasionally called just a permutation.
For a permutation , let be the number of cycles in . More accurately, the value of is defined as follows.
- Consider an undirected graph consisting of vertices numbered to . For each , add an edge connecting vertex and vertex . Then, let be the number of connected components in this graph.
You are given a permutation and an integer . Determine whether there is a permutation that satisfies the following condition, and construct one if it exists.
- Let to define a permutation .
- Then, holds.
For each input file, solve test cases.
Constraints
- is a permutation of .
- In each input file, the sum of does not exceed .
- All numbers in the input are integers.
Input
The input is given from Standard Input in the following format:
Each case is in the following format:
Output
For each case, if no permutation satisfies the condition, print No
. Otherwise, print your answer in the following format:
Yes
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.
3
3 3
1 3 2
2 2
2 1
4 8
1 2 3 4
Yes
2 1 3
No
Yes
1 2 3 4
In the first case, letting makes , satisfying .