201111: [AtCoder]ARC111 B - Reversible Cards

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

We have $N$ cards numbered $1$ to $N$. Each side of each card has a color represented by a positive integer.

One side of Card $i$ has a color $a_i$, and the other side has a color $b_i$.

For each card, you can choose which side shows up. Find the maximum possible number of different colors showing up.

Constraints

  • $1 \leq N \leq 200000$
  • $1 \leq a_i,b_i \leq 400000$
  • All numbers in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$a_1$ $b_1$
$a_2$ $b_2$
$:$
$a_N$ $b_N$

Output

Print the answer.


Sample Input 1

4
1 2
1 3
4 2
2 3

Sample Output 1

4

We can choose the sides with $1$, $3$, $4$, $2$ to have four colors.


Sample Input 2

2
111 111
111 111

Sample Output 2

1

They are painted with just one color.


Sample Input 3

12
5 2
5 6
1 2
9 7
2 7
5 5
4 2
6 7
2 2
7 8
9 7
1 8

Sample Output 3

8

Input

题意翻译

有 $n$ 卡片在桌子上,每张卡牌正反两面分别有一个颜色。第 $i$ 牌的正面的颜色为 $a_i$ ,背面为 $b_i$。 对于每张牌,可以选择正面或者背面朝上。所有可能的情况中出现的不同的颜色的数量的最大值。

加入题单

上一题 下一题 算法标签: