题目描述
Problem Background
Little $\iiint$ has no relation to this annoying construction.
Problem Description
A sequence $a$ is considered valid if it meets the following criteria:
- $a_i = -1$ or $a_i \in [1, n]$.
- For each $a_i \neq -1$, the graph formed by connecting $a_i$ to $i$ does not contain any cycles.
Given an integer $x$ and a sequence $a$ where all elements are within the range $[-1, n]$, you are required to replace all $a_i = 0$ with other integers such that $\sum_{i=1}^{n} a_i = x$ and $a$ is valid. If no such solution exists, report no solution.
Input Format
The first line contains two integers $n$ and $x$.
The second line contains $n$ integers representing the sequence $a$. It is guaranteed that $\forall a_i \in [-1, n]$.
Output Format
If there is no solution, output the string Rick. Otherwise, output $n$ integers representing the sequence $a$ after replacing all $0$ elements.
Sample Input and Output
Sample Input #1
6 -6
-1 -1 -1 0 0 0
Sample Output #1
-1 -1 -1 -1 -1 -1
Sample Input #2
6 14
0 1 4 0 1 4
Sample Output #2
-1 1 4 5 1 4
Sample Input #3
6 10
0 0 0 0 0 0
Sample Output #3
-1 -1 4 5 -1 4
Sample Input #4
6 6
1 1 0 0 0 0
Sample Output #4
Rick
Sample Input #5
6 40
0 0 0 0 0 0
Sample Output #5
Rick
Notes
This problem has subtasks.
| Subtask | Points | $n \le$ | $x \le$ | Special Conditions |
|---|---|---|---|---|
| #0 | $13$ | $15$ | $225$ | None |
| #1 | $24$ | $10^3$ | $10^9$ | None |
| #2 | $27$ | $10^5$ | $10^{18}$ | All $a_i = 0$ |
| #3 | $36$ | $10^5$ | $10^{18}$ | None |
For all data, $1 \le n \le 10^5, -10^{18} \le x \le 10^{18}$.
Special Judge Return Values
Accepted.The answer is correct.Oops, your answer is wrong. 1The answer is no solution, but the player's code outputs a solution.Oops, your answer is wrong. 2The sum of the player's output does not equal $x$.Oops, your answer is wrong. 3The player's output contains $0$.Oops, your answer is wrong. 4The player's output contains a cycle.Oops, your answer is wrong. 5The player's output changes positions of $a_i \neq 0$ from the input.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分