赞
踩
题目链接: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:
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:
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.
题目大意:给定两个数字
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。