当前位置:   article > 正文

Codeforces Round #698 (Div. 1) D. Nezzar and Hidden Permutations(高难度的构造问题)_codeforces round 698 (div. 1)

codeforces round 698 (div. 1)

题目链接:https://codeforces.com/contest/1477/problem/D

D. Nezzar and Hidden Permutations

time limit per test

5 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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 nn and mm. The game goes in the following way:

  • Firstly, Nezzar hides two permutations p1,p2,…,pnp1,p2,…,pn and q1,q2,…,qnq1,q2,…,qn of integers from 11 to nn, and Nanako secretly selects mm unordered pairs (l1,r1),(l2,r2),…,(lm,rm)(l1,r1),(l2,r2),…,(lm,rm);
  • After that, Nanako sends his chosen pairs to Nezzar;
  • On receiving those mm unordered pairs, Nezzar checks if there exists 1≤i≤m1≤i≤m, such that (pli−pri)(pli−pri) and (qli−qri)(qli−qri) have different signs. If so, Nezzar instantly loses the game and gets a score of −1−1. Otherwise, the score Nezzar gets is equal to the number of indices 1≤i≤n1≤i≤n such that pi≠qipi≠qi.

However, Nezzar accidentally knows Nanako's unordered pairs and decides to take advantage of them. Please help Nezzar find out two permutations pp and qq such that the score is maximized.

Input

The first line contains a single integer tt (1≤t≤5⋅1051≤t≤5⋅105) — the number of test cases.

The first line of each test case contains two integers n,mn,m (1≤n≤5⋅105,0≤m≤min(n(n−1)2,5⋅105)1≤n≤5⋅105,0≤m≤min(n(n−1)2,5⋅105)).

Then mm lines follow, ii-th of them contains two integers li,rili,ri (1≤li,ri≤n1≤li,ri≤n, li≠rili≠ri), describing the ii-th unordered pair Nanako chooses. It is guaranteed that all mm unordered pairs are distinct.

It is guaranteed that the sum of nn for all test cases does not exceed 5⋅1055⋅105, and the sum of mm for all test cases does not exceed 5⋅1055⋅105.

Output

For each test case, print two permutations p1,p2,…,pnp1,p2,…,pn and q1,q2,…,qnq1,q2,…,qn such that the score Nezzar gets is maximized.

Example

input

Copy

  1. 3
  2. 4 2
  3. 1 2
  4. 3 4
  5. 6 4
  6. 1 2
  7. 1 3
  8. 3 5
  9. 3 6
  10. 2 1
  11. 1 2

output

Copy

  1. 1 2 3 4
  2. 3 4 1 2
  3. 2 3 4 1 6 5
  4. 1 4 3 2 5 6
  5. 1 2
  6. 1 2

Note

For first test case, for each pair given by Nanako:

  • for the first pair (1,2)(1,2): p1−p2=1−2=−1p1−p2=1−2=−1, q1−q2=3−4=−1q1−q2=3−4=−1, they have the same sign;
  • for the second pair (3,4)(3,4): p3−p4=3−4=−1p3−p4=3−4=−1, q3−q4=1−2=−1q3−q4=1−2=−1, they have the same sign.

As Nezzar does not lose instantly, Nezzar gains the score of 44 as pi≠qipi≠qi for all 1≤i≤41≤i≤4. Obviously, it is the maximum possible score Nezzar can get.

题目大意:给定两个数字

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/75426
推荐阅读
相关标签
  

闽ICP备14008679号