#P12502. 「CEOI2025」BoardOina 游戏
「CEOI2025」BoardOina 游戏
Description
Every year, a big Boardgame Expo takes place in Cluj-Napoca, showcasing a wide selection of new games. The main attraction this year is a game called BoardOina.
There are players lined up in a queue, waiting to try out the game. Players are numbered from to in their order in the queue. Player is at the front of the queue and player is at the back.
There are distinct friendship relations between pairs of players in the queue. Specifically, for each from to , inclusive, player and player are friends, where . Friendship relations are symmetric.
Consider a sequence of consecutive players in the queue starting at player (for any and such that and ). This sequence of players forms a friend group of size if for all pairs of two players, they are connected by a sequence of friendship relations within that friend group. Specifically, players form a friend group of size if, for each and such that , there exists a sequence of players such that:
- ;
- for each from to , inclusive;
- and ;
- players and are friends for each from to , inclusive.
Note that in the case of , player alone forms a friend group of size .
BoardOina can be played by any number of players. However, to make the game more successful, the organizers only let friend groups play it.
Only one group can play at a time. For each game, a friend group starting at the player at the front of the queue is formed, and starts playing the game. The players in this friend group are removed from the queue. This process is repeated until the queue becomes empty. Formally, we say that the queue can be partitioned into friend groups if there exists an array of group sizes, , such that each of the following conditions holds.
- and (for each such that );
- ;
- for each between and , inclusive, players form a friend group of size , where and otherwise .
The organizers want to minimize the number of friend groups that play the game. That is, they want to partition the queue into friend groups such that it is not possible to partition the queue into (or less) friend groups.
Your task is to find a partitioning of the queue into a minimum number of friend groups, and report the array of group sizes.
Implementation Details
You should implement the following procedure.
std::vector<int> partition_players(int n, int m, std::vector<int> X, std::vector<int> Y)
n
: the number of players in the queue.m
: the number of friendship relations.X
,Y
: arrays of length describing friendship relations.- This procedure should return an array of group sizes, representing a partition of the player queue into a minimum number of friend groups.
- This procedure is called exactly once for each test case.
Constraints
- (for each such that )
- Friendship relations are distinct. In other words, or (for each and such that )
- If there are multiple solutions with minimum number of groups, you can return any valid solution.
Subtasks
- (5 points) for each from to , inclusive.
- (7 points) for each from to , inclusive.
- (6 points) and
- (15 points) and
- (34 points) There are no friendship relations which are cyclic. That is, for any sequence of distinct players , such that and for each players and are friends, players and are not friends.
- (33 points) No additional constraints.
Sample 1
Consider the following call:
partition_players(5, 3, {0, 1, 3}, {1, 4, 4})
In this example, players and , players and , and players and are friends.
Player has no friends in the queue, hence there must be a friend group formed by player alone, which means that the minimum number of friend groups is . On the other hand, players and , as well as players and can form a friend group of size .
Therefore, the queue can be partitioned into friend groups of sizes , and , so the procedure may return [2, 1, 2]
.
Sample 2
Consider the following call:
partition_players(7, 6, {0, 4, 2, 1, 2, 3}, {1, 5, 4, 5, 5, 6})
In this example, players and , players and , players and , players and , players and and players and are friends.
The only friend of player is player , so any friend group containing player is either
- a friend group of size containing player alone, or
- a friend group containing both player and player .
A friend group in the second case must also contain players and . This is not possible as the only friend of player is player , so player is not connected to players and by a sequence of friendship relations.
Therefore, player must be placed in a friend group of size . Similarly, player must also be placed in a friend group of size , therefore the number of friend groups in a partition is at least .
Players , and do not form a friend group of size , as neither player or player is connected to player by a sequence of friendship relations within the group. That would have not been the case if was in the group, but since and will definitely be in different groups, that will never happen. That is, the number of friend groups in a partition is at least .
On the other hand, players and , and players and form two friend groups of size .
Therefore, the queue can be partitioned into friend groups of sizes , , , and . The procedure may return [2, 1, 1, 2, 1]
.
Sample Grader
The sample grader reads the input in the following format:
- line :
- line ():
Let the elements of the array returned by partition_players
be for some nonnegative . The output of the sample grader is in the following format:
- line :
- line :