#P4155. [SCOI2015] 国旗计划

[SCOI2015] 国旗计划

Description

Country A is carrying out a great plan — the National Flag Plan. In this plan, border guards will run a full loop along the border line in relay while holding the national flag. This requires multiple border guards working together in relay. The National Security Agency has selected NN outstanding border guards as candidates.

Country A is vast, and there are MM border posts on the border line, numbered 11 to MM clockwise. Each border guard is based at two border posts and is skilled at long-distance running between these two posts. We call the path between these two posts the guard’s running interval. The NN guards are carefully selected and in excellent physical condition, so no guard’s running interval is contained within another guard’s running interval.

The director of the National Security Agency wants to know the minimum number of border guards whose running intervals can cover the entire border line to successfully complete the National Flag Plan. Moreover, for each border guard, under the condition that he must participate, the director also wants to know the minimum number of border guards required to cover the entire border line.

Input Format

The first line contains two positive integers N,MN, M, the number of border guards and the number of border posts.

Then follow NN lines, each containing two positive integers. On the ii-th line, the two integers Ci,DiC_i, D_i denote the indices of the two border posts where guard ii is based. The running interval of guard ii is from post CiC_i to post DiD_i in the clockwise direction. It is guaranteed that the entire border line can be covered.

Output Format

Output a single line containing NN positive integers. The jj-th integer denotes, under the condition that guard jj must participate, the minimum number of border guards required to successfully complete the National Flag Plan.

4 8
2 5
4 7
6 1
7 3
3 3 4 3

Hint

Constraints: $N \leq 2 \times 10^5, M < 10^9, 1 \leq C_i, D_i \leq M$.

Translated by ChatGPT 5