#P16271. [蓝桥杯 2026 省 Java B 组] 擂台赛
[蓝桥杯 2026 省 Java B 组] 擂台赛
Problem Description
Xiao Lan wants to organize an arena match. There are players, numbered from to . Initially, each player is on their own arena . Each player has exactly one target arena that they want to go to and challenge.
Before the match starts, Xiao Lan needs to decide an order in which the players will act. Following this order, for each player who acts:
- If their target arena has not been closed yet, they will leave their own arena and go to arena to challenge, and at the same time close their original arena .
- If their target arena has already been closed, then they cannot start the challenge and can only stay where they are.
Xiao Lan wants to choose an order so that in the end, the number of arenas that have been used (i.e., successfully visited as a challenge target) is as small as possible. Note that players who stay where they are do not count as using an arena.
Please help Xiao Lan compute: under the best acting order, what is the minimum number of arenas that will be used?
Input Format
The input has 2 lines.
The first line contains a positive integer , representing the number of players.
The second line contains positive integers , representing the target arena number for each player.
Output Format
Output one integer, representing the minimum number of arenas that have been used.
5
2 3 4 5 4
2
Hint
Sample Explanation
One optimal acting order is: .
- Player challenges : target arena is not closed, the action succeeds, arena is closed, arena is used;
- Player challenges : target arena is not closed, the action succeeds, arena is closed, arena is used;
- Player challenges : target arena was closed when player acted, so player can only stay where they are;
- Player challenges : target arena is not closed, the action succeeds, arena is closed, arena is used;
- Player challenges : target arena was closed when player acted, so player can only stay where they are.
In the end, the arenas that have been used are , a total of .
Constraints and Notes
For of the testdata, .
For of the testdata, , , and .
Translated by ChatGPT 5