CF1477D.Nezzar and Hidden Permutations
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Nezzar designs a brand new game "Hidden Permutations" and shares it with his best friend, Nanako.
At the beginning of the game, Nanako and Nezzar both know integers n and m . The game goes in the following way:
- Firstly, Nezzar hides two permutations p1,p2,…,pn and q1,q2,…,qn of integers from 1 to n , and Nanako secretly selects m unordered pairs (l1,r1),(l2,r2),…,(lm,rm) ;
- After that, Nanako sends his chosen pairs to Nezzar;
- On receiving those m unordered pairs, Nezzar checks if there exists 1≤i≤m , such that (pli−pri) and (qli−qri) have different signs. If so, Nezzar instantly loses the game and gets a score of −1 . Otherwise, the score Nezzar gets is equal to the number of indices 1≤i≤n such that pi=qi .
However, Nezzar accidentally knows Nanako's unordered pairs and decides to take advantage of them. Please help Nezzar find out two permutations p and q such that the score is maximized.
输入格式
The first line contains a single integer t ( 1≤t≤5⋅105 ) — the number of test cases.
The first line of each test case contains two integers n,m ( 1≤n≤5⋅105,0≤m≤min(2n(n−1),5⋅105) ).
Then m lines follow, i -th of them contains two integers li,ri ( 1≤li,ri≤n , li=ri ), describing the i -th unordered pair Nanako chooses. It is guaranteed that all m unordered pairs are distinct.
It is guaranteed that the sum of n for all test cases does not exceed 5⋅105 , and the sum of m for all test cases does not exceed 5⋅105 .
输出格式
For each test case, print two permutations p1,p2,…,pn and q1,q2,…,qn such that the score Nezzar gets is maximized.
输入输出样例
输入#1
3 4 2 1 2 3 4 6 4 1 2 1 3 3 5 3 6 2 1 1 2
输出#1
1 2 3 4 3 4 1 2 2 3 4 1 6 5 1 4 3 2 5 6 1 2 1 2
说明/提示
For first test case, for each pair given by Nanako:
- for the first pair (1,2) : p1−p2=1−2=−1 , q1−q2=3−4=−1 , they have the same sign;
- for the second pair (3,4) : p3−p4=3−4=−1 , q3−q4=1−2=−1 , they have the same sign.
As Nezzar does not lose instantly, Nezzar gains the score of 4 as pi=qi for all 1≤i≤4 . Obviously, it is the maximum possible score Nezzar can get.