#P16280. 「MierOI R1」Eternal
「MierOI R1」Eternal
Problem Description
Given closed intervals . Find the maximum number of intervals that can be selected such that all intersecting intervals among the selected ones share a common endpoint.
Two closed intervals are said to intersect if and only if and .
Two closed intervals are said to share a common endpoint if and only if , , , or .
Input Format
This problem contains multiple test cases.
The first line of the input contains a positive integer , indicating the number of test cases.
Then, the test cases follow sequentially. For each test case:
- The first line contains a positive integer .
- The next lines each contain two positive integers .
Output Format
For each test case, output a single line containing a non-negative integer, representing the maximum number of intervals that can be selected.
4
3
1 3
2 2
1 1
5
1 3
2 3
4 5
3 5
1 4
8
1 4
2 4
3 4
1 2
2 3
1 3
3 5
4 5
16
1 4
2 4
3 4
1 2
2 3
1 3
3 5
4 5
5 8
6 8
7 8
5 6
6 7
5 7
7 9
8 9
2
4
6
12
Hint
Explanation for Sample #1
For the first test case, we can select 2 intervals: and . It can be proven that there is no way to select more intervals.
For the second test case, we can select 4 intervals: , and . It can be proven that there is no way to select more intervals.
Data Range
This problem uses bundled subtasks.
For all test cases, it is guaranteed that , , and .
::cute-table{tuack}
| Subtask | Special Property | Score | |
|---|---|---|---|
| None | |||
| ^ | |||
| A | |||
| ^ | B | ||
| None |
- Special Property A: Any two given intervals do not share a common endpoint.
- Special Property B: Any two given intervals intersect.