atcoder#ARC126B. [ARC126B] Cross-free Matching
[ARC126B] Cross-free Matching
Score : points
Problem Statement
In the coordinate plane, we have vertices whose -coordinates are and whose -coordinates are or : . There are segments that connect two of these vertices: the -th segment connects and .
Consider choosing of these segments so that no two chosen segments contain the same point. Here, we consider both endpoints of a segment to be contained in that segment. Find the maximum possible value of .
Constraints
- or , if .
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible value of .
3 3
1 2
2 3
3 1
2
One optimal solution is to choose the first and second segments.
The first and third segments, for example, contain the same point , so we cannot choose them both.
3 5
1 1
2 1
2 2
3 2
3 3
3
One optimal solution is to choose the first, third, and fifth segments.
The first and second segments, for example, contain the same point , so we cannot choose them both.
7 5
1 7
7 1
3 4
2 6
5 2
1