33OJ
登录 注册

#P17823. [COCI 2026/2027 #1] Karte

    ID: 20477 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>并查集图论建模COCI(克罗地亚)2026

[COCI 2026/2027 #1] Karte

Problem Description

Lucija has nn cards arranged in a row. Every card has two sides with one color on each side: one side of the ii-th card has color AiA_i, and the other side has color BiB_i. Colors are labelled with positive integers, and the two sides of a card may also have the same color.

Lucija puts cards on the table, and for each card she chooses which side faces up. One color from each card is then visible on the table. Lucija wants as many different colors as possible to be visible.

She has not yet decided how many cards to put on the table, so you want to know the answer for every possible number. For each kk from 11 to nn, find the largest number of different colors that can be visible if Lucija puts only the first kk cards on the table.

For each kk, the sides of the cards are chosen independently: the same card may face different sides up for different values of kk.

Input Format

The first line contains a positive integer nn (1≤n≤100 0001\le n\le 100\,000), the number of cards.

The ii-th of the following nn lines contains positive integers AiA_i and BiB_i (1≤Ai,Bi≤100 0001\le A_i,B_i\le 100\,000), the colors on the two sides of the ii-th card.

Output Format

In the only line, output nn numbers separated by spaces. The kk-th number should be the largest number of different colors that can be visible on the table if only the first kk cards are on it.

4
1 2
2 3
1 3
3 3
1 2 3 3
6
5 5
5 5
7 5
2 9
9 2
2 9
1 1 2 3 4 4
5
4 4
4 1
2 3
4 2
1 1
1 2 3 4 4

Hint

Clarification of the first example

With one card, one color is visible. With the first two cards, (1,2)(1,2) and (2,3)(2,3), two different colors can be visible, for example 11 and 22. With the first three cards, all three colors can be visible: the first card shows color 22, the second color 33, and the third color 11. The fourth card has color 33 on both sides, so it cannot add a new color, and the answer stays 33.

Clarification of the second example

The first two cards have color 55 on both sides, so only one color is visible with them. The third card shows color 77, and the fourth and fifth cards show colors 22 and 99. The sixth card has the same colors as the fourth one, and both are already visible, so the answer for k=6k=6 is also 44.

Clarification of the third example

For k=3k=3, the third card (2,3)(2,3) may show either of its colors, for example color 22. For k=4k=4, the first card has to show color 44, so the second card shows color 11, the fourth card (4,2)(4,2) shows color 22, and the third card shows color 33. This way all four colors are visible. The third card faces different sides up for k=3k=3 and k=4k=4, which is allowed.

Scoring

Subtask Points Constraints
1 13 n≤10n\le 10.
2 17 At most 55 different colors appear on all the cards in total.
3 21 n≤1000n\le 1000.
4 19 No additional constraints.