PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000157. Ông già Noel bí mật (Secret Santa)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ông già Noel bí mật (Secret Santa)
Secret Santa
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are employees numbered from to . Each employee wishes to give a gift to employee . Assign a distinct recipient to each employee, with , maximizing the number of fulfilled wishes .
Input
The first line contains . The second line contains integers , where is employee 's wished recipient.
Output
Print the maximum number of fulfilled wishes and, on the next line, a permutation with and exactly equalities .
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3
2 1 2
Output
2
3 1 2
Explanation
Employees and both request recipient , so all three wishes cannot be fulfilled. The assignment is a derangement and fulfills the wishes of employees and , reaching the upper bound .