아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Exactly One Point

면접 대비

시간 제한2초메모리 제한512 MB

요약
n개의 선분이 주어질 때, 각 선분이 정확히 한 점을 포함하고 모든 점이 어떤 선분에 속하도록 서로 다른 점을 배치하거나 불가능함을 판별한다.
난이도

보통10점 중 5점

유형
그리디, 구간, 정렬
정답자
아직 제출이 없습니다

문제

There are nn segments on a line. You should place some points onto this line so that:

  • every point is contained in at least one segment,
  • every segment contains exactly one point.

입력

The first line contains an integer nn (1≤n≤2000001 \le n \le 200000) --- the number of segments.

Each of the next nn lines contains two integers L_iL\_i and R_iR\_i (L_i<R_iL\_i < R\_i) --- the endpoints of the ii-th segment.

For convenience, all endpoints of all segments are even numbers from 00 to 4n−24n - 2.

출력

If it's impossible to place points in a required way, output "-1".

Otherwise, in the first line output an integer mm --- the number of points that should be placed onto the line.

In the next line, output mm distinct integers from 00 to 4n−24n - 2 --- the coordinates of the points.

You don't have to minimize the number of points. If there are several possible solutions, output any of them.

예제3

  1. 예제 1

    입력
    3
    0 10
    2 4
    6 8
    
    예상 출력
    -1
    
  2. 예제 2

    입력
    2
    0 6
    2 4
    
    예상 출력
    1
    4
    
  3. 예제 3

    입력
    3
    0 2
    2 4
    4 6
    
    예상 출력
    3
    1 3 6