CF1477D.Nezzar and Hidden Permutations

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

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 1≤i≤m1 \le i \le m, such that (pli−pri)(p_{l_i}-p_{r_i}) and (qli−qri)(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 1≤i≤n1 \le i \le n such that pi≠qip_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.

Nezzar 设计了一款全新的游戏“隐藏排列”,并与他最好的朋友 Nanako 一起分享。

游戏开始时,Nanako 和 Nezzar 都知道两个整数 nn 和 mm。游戏流程如下:

  • 首先,Nezzar 隐藏两个 11 到 nn 的排列:p1,p2,…,pnp_1,p_2,\ldots,p_n 和 q1,q2,…,qnq_1,q_2,\ldots,q_n;同时,Nanako 秘密地选出 mm 个无序对 (l1,r1),(l2,r2),…,(lm,rm)(l_1,r_1),(l_2,r_2),\ldots,(l_m,r_m);
  • 接着,Nanako 将他所选的这些无序对发送给 Nezzar;
  • Nezzar 收到这 mm 个无序对后,检查是否存在某个 1≤i≤m1 \le i \le m,使得 (pli−pri)(p_{l_i}-p_{r_i}) 与 (qli−qri)(q_{l_i}-q_{r_i}) 符号不同(即一正一负)。若存在这样的 ii,则 Nezzar 立即输掉游戏,并得分为 −1-1;否则,Nezzar 的得分等于满足 pi≠qip_i \neq q_i 的下标 ii(其中 1≤i≤n1 \le i \le n)的个数。

然而,Nezzar 不慎提前获知了 Nanako 所选的无序对,并决定利用这一信息。请帮助 Nezzar 找出两个排列 pp 和 qq,使得其得分最大化。

输入格式

The first line contains a single integer tt (1≤t≤5⋅1051 \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 (1≤n≤5⋅105,0≤m≤min⁡(n(n−1)2,5⋅105)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 (1≤li,ri≤n1 \le l_i,r_i \le n, li≠ril_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 5⋅1055 \cdot 10^5, and the sum of mm for all test cases does not exceed 5⋅1055\cdot 10^5.

第一行包含一个整数 tt(1≤t≤5⋅1051 \le t \le 5 \cdot 10^5),表示测试用例的数量。

每个测试用例的第一行包含两个整数 n,mn,m(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5,0≤m≤min⁡(n(n−1)2,5⋅105)0 \le m \le \min(\frac{n(n-1)}{2},5 \cdot 10^5))。

接下来是 mm 行,其中第 ii 行包含两个整数 li,ril_i,r_i(1≤li,ri≤n1 \le l_i,r_i \le n,li≠ril_i \neq r_i),描述 Nanako 选择的第 ii 个无序对。保证这 mm 个无序对互不相同。

保证所有测试用例的 nn 之和不超过 5⋅1055 \cdot 10^5,且所有测试用例的 mm 之和不超过 5⋅1055 \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.

对于每个测试用例,输出两个排列 p1,p2,…,pnp_1,p_2,\ldots,p_n 和 q1,q2,…,qnq_1,q_2,\ldots,q_n,使得 Nezzar 得到的分数最大化。

输入输出样例

  • 输入#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): p1−p2=1−2=−1p_1 - p_2 = 1 - 2 = -1, q1−q2=3−4=−1q_1 - q_2 = 3 - 4 = -1, they have the same sign;
  • for the second pair (3,4)(3,4): p3−p4=3−4=−1p_3 - p_4 = 3 - 4 = -1, q3−q4=1−2=−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 pi≠qip_i \neq q_i for all 1≤i≤41 \leq i \leq 4. Obviously, it is the maximum possible score Nezzar can get.

对于第一个测试用例,针对 Nanako 给出的每一对数:

  • 对于第一对 (1,2)(1,2):p1−p2=1−2=−1p_1 - p_2 = 1 - 2 = -1,q1−q2=3−4=−1q_1 - q_2 = 3 - 4 = -1,二者符号相同;
  • 对于第二对 (3,4)(3,4):p3−p4=3−4=−1p_3 - p_4 = 3 - 4 = -1,q3−q4=1−2=−1q_3 - q_4 = 1 - 2 = -1,二者符号相同。

由于 Nezzar 并未立即失败,且对所有 1≤i≤41 \leq i \leq 4 均有 pi≠qip_i \neq q_i,Nezzar 获得分数 44。显然,这是 Nezzar 能获得的最高可能得分。

输入解题思路,AI测评打分。不知道怎么写?

首页