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

  • Firstly, Nezzar hides two permutations p1,p2,,pnp_1,p_2,\ldots,p_n and q1,q2,,qnq_1,q_2,\ldots,q_n of integers from 11 to nn , and Nanako secretly selects mm unordered pairs (l1,r1),(l2,r2),,(lm,rm)(l_1,r_1),(l_2,r_2),\ldots,(l_m,r_m) ;
  • After that, Nanako sends his chosen pairs to Nezzar;
  • On receiving those mm unordered pairs, Nezzar checks if there exists 1im1 \le i \le m , such that (plipri)(p_{l_i}-p_{r_i}) and (qliqri)(q_{l_i}-q_{r_i}) 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 1in1 \le i \le n such that piqip_i \neq q_i .

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.

输入格式

The first line contains a single integer tt ( 1t51051 \le t \le 5 \cdot 10^5 ) — the number of test cases.

The first line of each test case contains two integers n,mn,m ( 1n5105,0mmin(n(n1)2,5105)1 \le n \le 5 \cdot 10^5, 0 \le m \le \min(\frac{n(n-1)}{2},5 \cdot 10^5) ).

Then mm lines follow, ii -th of them contains two integers li,ril_i,r_i ( 1li,rin1 \le l_i,r_i \le n , liril_i \neq r_i ), 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 51055 \cdot 10^5 , and the sum of mm for all test cases does not exceed 51055\cdot 10^5 .

输出格式

For each test case, print two permutations p1,p2,,pnp_1,p_2,\ldots,p_n and q1,q2,,qnq_1,q_2,\ldots,q_n 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)(1,2) : p1p2=12=1p_1 - p_2 = 1 - 2 = -1 , q1q2=34=1q_1 - q_2 = 3 - 4 = -1 , they have the same sign;
  • for the second pair (3,4)(3,4) : p3p4=34=1p_3 - p_4 = 3 - 4 = -1 , q3q4=12=1q_3 - q_4 = 1 - 2 = -1 , they have the same sign.

As Nezzar does not lose instantly, Nezzar gains the score of 44 as piqip_i \neq q_i for all 1i41 \leq i \leq 4 . Obviously, it is the maximum possible score Nezzar can get.

首页