P4704 Taiji Sword

Description

After learning Taiji, Bob asks Alice to teach him the Taiji Sword. Alice tells him he must first pass a basic swordsmanship test. The test requires Bob to cut $n$ ropes as quickly as possible. All rope endpoints are pairwise distinct, so there are $2n$ endpoints in total. These endpoints are tied on a circle, evenly spaced. We number these endpoints clockwise from $1$ to $2n$. Each of Bob’s cuts is a straight line, and it severs every rope that intersects this line. He wants to know the minimum number of cuts needed to cut all the ropes.

Input Format

The first line contains an integer $n(1 \leq n \leq 2 \times 10^5)$, representing the number of ropes. The next $n$ lines each contain two integers $a_i, b_i(1 \leq a_i, b_i \leq 2n, a_i \not= b_i)$, indicating the indices of the two endpoints of the $i$-th rope.

Output Format

Output a single integer, the answer.

Explanation/Hint

Explanation for Sample 1: ![](https://cdn.luogu.com.cn/upload/pic/19179.png) Explanation for Sample 2: ![](https://cdn.luogu.com.cn/upload/pic/19180.png) Explanation for Sample 3: ![](https://cdn.luogu.com.cn/upload/pic/19181.png) Translated by ChatGPT 5