luogu#P4704. 太极剑

太极剑

Problem 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 nn ropes as quickly as possible.

All rope endpoints are pairwise distinct, so there are 2n2n endpoints in total. These endpoints are tied on a circle, evenly spaced. We number these endpoints clockwise from 11 to 2n2n.

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(1n2×105)n(1 \leq n \leq 2 \times 10^5), representing the number of ropes.

The next nn lines each contain two integers ai,bi(1ai,bi2n,aibi)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 ii-th rope.

Output Format

Output a single integer, the answer.

2
1 2
3 4
1
3
1 2
3 4
5 6
2
3
1 3
2 4
5 6
1

Hint

Explanation for Sample 1:

Explanation for Sample 2:

Explanation for Sample 3:

Translated by ChatGPT 5