Same Segment

시간 제한1초메모리 제한1024 MB

요약
M개의 구간이 주어질 때, 각 구간의 합이 모두 K가 되는 0 이상 K 이하 값의 수열이 존재하는지 판정하고, 존재하면 하나를 출력한다.
난이도

보통10점 중 7점

유형
그래프, 누적 합, 유니온 파인드
정답자
아직 제출이 없습니다

문제

You have a sequence aa of NN integers between 00 and KK inclusive. MM segments are given, where iith segment is \[l_i,r_i]\[l\_i,r\_i]. We want ∑_j=l_ir_ia_j=K\sum\_{j=l\_i}^{r\_i}a\_j=K to satisfy for every segment. Determine whether there exists such sequence aa.

입력

Each test data contains one or more test cases. The first line contains an integer TT — the number of test cases for this input file.

First line of each test case contains 33 integers NN, MM, KK.

ii-th of the next MM lines contain two integers l_il\_i and r_ir\_i: left and right end of ii-th segment.

출력

For each test case, if a sequence that satisfies the condition exists, output the elements of the sequence. In case of multiple answers you may output any of them.

If no valid sequence exists, output a single integer −1-1.

제한

  • 1≤T≤1051\leq T\leq 10^5
  • 2≤N≤4×1052\leq N\leq 4\times 10^5
  • 1≤M≤min⁡(2×105,N(N+1)2)1\leq M\leq\min\left( 2\times 10^5,\frac{N(N+1)}{2} \right)
  • 1≤K≤201\leq K\leq 20
  • 1≤l_i≤r_i≤N1\leq l\_i\leq r\_i\leq N
  • (l_i,r_i)≠(l_j,r_j)(l\_i,r\_i)\neq(l\_j,r\_j) for i≠ji\neq j
  • Sum of NN over every test case does not exceed 4×1054\times 10^5.
  • Sum of MM over every test case does not exceed 2×1052\times 10^5.

예제1

  1. 예제 1

    입력
    4
    6 3 3
    1 3
    2 4
    3 5
    4 6 2
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    4 4 1
    1 2
    3 4
    1 3
    2 4
    3 3 10
    1 1
    2 2
    3 3
    
    예상 출력
    1 1 1 1 1 1
    -1
    1 0 0 1
    10 10 10