[Solution] Strict Permutation CodeChef Solution
You are given an integer . You have to find a permutation of the integers that satisfies conditions of the following form:
- , denoting that the element must appear in the prefix of length . Formally, if the index of the element is (i.e, ), then the condition must hold.
Print -1
if no such permutation exists. In case multiple permutations that satisfy all the conditions exist, find the lexicographically smallest one.
Note: If two arrays and have the same length , then is called lexicographically smaller
👇👇👇👇👇
than only if there exists an index such that .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
Passes for Fair CodeChef Solution
Fill Candies CodeChef Solution
Make Palindrome 2 CodeChef Solution
Fill The Grid CodeChef Solution
- The first line of each test case contains two space-separated integers and — the length of permutation and the number of conditions to be satisfied respectively.
- The next lines describe the conditions. The -th of these lines contains two space-separated integers and .
Output Format
For each test case, output a single line containing the answer:
- If no permutation satisfies the given conditions, print
−1
. - Otherwise, print space-separated integers, denoting the elements of the permutation. If there are multiple answers, output the lexicographically smallest one.
Constraints
- for each .
- The sum of over all test cases won't exceed .
No comments:
Post a Comment