#P10693. [SNCPC2024] 换座位
[SNCPC2024] 换座位
Problem Description
The Tree Kingdom is preparing to hold a grand celebration.
As the celebration designer of the Tree Kingdom, Shirost plans to invite guests to attend. There are seats prepared for the celebration. Each seat can have at most one person, and each person must sit in exactly one seat. Shirost’s initial plan is to arrange guest to sit in seat . However, the president investigated the wishes of these guests: guest ’s preferred seat is seat . But unless they can sit in their preferred seat, they are only willing to sit in their original seat. The president hopes Shirost can modify the plan so that as many guests as possible can sit in their preferred seats.
Formally, you need to find an array of length () such that and or , and maximize the number of indices with .
You only need to output this maximum number.
Input Format
The first line contains an integer (), representing the total number of people.
The second line contains integers (), separated by spaces, representing each person’s preferred seat.
Output Format
Output only one line with one integer, representing the maximum number of guests who can sit in their preferred seats.
5
2 6 4 5 3
5
Hint
For the first sample, everyone can switch to their preferred seat.
Translated by ChatGPT 5