#P17823. [COCI 2026/2027 #1] Karte
[COCI 2026/2027 #1] Karte
Problem Description
Lucija has cards arranged in a row. Every card has two sides with one color on each side: one side of the -th card has color , and the other side has color . 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 from to , find the largest number of different colors that can be visible if Lucija puts only the first cards on the table.
For each , the sides of the cards are chosen independently: the same card may face different sides up for different values of .
Input Format
The first line contains a positive integer (), the number of cards.
The -th of the following lines contains positive integers and (), the colors on the two sides of the -th card.
Output Format
In the only line, output numbers separated by spaces. The -th number should be the largest number of different colors that can be visible on the table if only the first 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, and , two different colors can be visible, for example and . With the first three cards, all three colors can be visible: the first card shows color , the second color , and the third color . The fourth card has color on both sides, so it cannot add a new color, and the answer stays .
Clarification of the second example
The first two cards have color on both sides, so only one color is visible with them. The third card shows color , and the fourth and fifth cards show colors and . The sixth card has the same colors as the fourth one, and both are already visible, so the answer for is also .
Clarification of the third example
For , the third card may show either of its colors, for example color . For , the first card has to show color , so the second card shows color , the fourth card shows color , and the third card shows color . This way all four colors are visible. The third card faces different sides up for and , which is allowed.
Scoring
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 13 | . |
| 2 | 17 | At most different colors appear on all the cards in total. |
| 3 | 21 | . |
| 4 | 19 | No additional constraints. |