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

题目链接: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

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

output

Copy

1 2 3 4
3 4 1 2
2 3 4 1 6 5
1 4 3 2 5 6
1 2
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.

题目大意:给定两个数字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值