CF1697F.Too Many Constraints
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are asked to build an array a , consisting of n integers, each element should be from 1 to k .
The array should be non-decreasing ( ai≤ai+1 for all i from 1 to n−1 ).
You are also given additional constraints on it. Each constraint is of one of three following types:
- 1 i x : ai should not be equal to x ;
- 2 i j x : ai+aj should be less than or equal to x ;
- 3 i j x : ai+aj should be greater than or equal to x .
Build any non-decreasing array that satisfies all constraints or report that no such array exists.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of testcases.
The first line of each testcase contains three integers n,m and k ( 2≤n≤2⋅104 ; 0≤m≤2⋅104 ; 2≤k≤10 ).
The i -th of the next m lines contains a description of a constraint. Each constraint is of one of three following types:
- 1 i x ( 1≤i≤n ; 1≤x≤k ): ai should not be equal to x ;
- 2 i j x ( 1≤i<j≤n ; 2≤x≤2⋅k ): ai+aj should be less than or equal to x ;
- 3 i j x ( 1≤i<j≤n ; 2≤x≤2⋅k ): ai+aj should be greater than or equal to x .
The sum of n over all testcases doesn't exceed 2⋅104 . The sum of m over all testcases doesn't exceed 2⋅104 .
输出格式
For each testcase, determine if there exists a non-decreasing array that satisfies all conditions. If there is no such array, then print -1. Otherwise, print any valid array — n integers from 1 to k .
输入输出样例
输入#1
4 4 0 4 2 2 3 3 1 2 3 1 2 2 3 3 2 1 1 1 2 2 3 2 3 2 3 2 5 5 5 3 2 5 7 2 4 5 10 3 4 5 6 3 3 4 7 2 1 5 7
输出#1
1 2 3 4 1 3 -1 1 2 2 5 5