Reversible Cards

AtCoder
IDarc111_b
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
4
1 2
1 3
4 2
2 3
Output #1
4

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

They are painted with just one color.
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
Output #3
8
API Response (JSON)
{
  "problem": {
    "name": "Reversible Cards",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc111_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have $N$ cards numbered $1$ to $N$. Each side of each card has a color represented by a positive integer.\nOne side of Card $i$ has a color $a_i$, and the other side has a color $b_i$.\nFor each card...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments