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 n and m. The game goes in the following way:
- Firstly, Nezzar hides two permutations p1,p2,…,pn and q1,q2,…,qn of integers from 1 to n, and Nanako secretly selects m unordered pairs (l1,r1),(l2,r2),…,(lm,rm);
- After that, Nanako sends his chosen pairs to Nezzar;
- On receiving those m unordered pairs, Nezzar checks if there exists 1≤i≤m, such that (pli−pri) and (qli−qri) have different signs. If so, Nezzar instantly loses the game and gets a score of −1. Otherwise, the score Nezzar gets is equal to the number of indices 1≤i≤n such that pi=qi.
However, Nezzar accidentally knows Nanako's unordered pairs and decides to take advantage of them. Please help Nezzar find out two permutations p and q such that the score is maximized.
Nezzar 设计了一款全新的游戏“隐藏排列”,并与他最好的朋友 Nanako 一起分享。
游戏开始时,Nanako 和 Nezzar 都知道两个整数 n 和 m。游戏流程如下:
- 首先,Nezzar 隐藏两个 1 到 n 的排列:p1,p2,…,pn 和 q1,q2,…,qn;同时,Nanako 秘密地选出 m 个无序对 (l1,r1),(l2,r2),…,(lm,rm);
- 接着,Nanako 将他所选的这些无序对发送给 Nezzar;
- Nezzar 收到这 m 个无序对后,检查是否存在某个 1≤i≤m,使得 (pli−pri) 与 (qli−qri) 符号不同(即一正一负)。若存在这样的 i,则 Nezzar 立即输掉游戏,并得分为 −1;否则,Nezzar 的得分等于满足 pi=qi 的下标 i(其中 1≤i≤n)的个数。
然而,Nezzar 不慎提前获知了 Nanako 所选的无序对,并决定利用这一信息。请帮助 Nezzar 找出两个排列 p 和 q,使得其得分最大化。
输入格式
The first line contains a single integer t (1≤t≤5⋅105) — the number of test cases.
The first line of each test case contains two integers n,m (1≤n≤5⋅105,0≤m≤min(2n(n−1),5⋅105)).
Then m lines follow, i-th of them contains two integers li,ri (1≤li,ri≤n, li=ri), describing the i-th unordered pair Nanako chooses. It is guaranteed that all m unordered pairs are distinct.
It is guaranteed that the sum of n for all test cases does not exceed 5⋅105, and the sum of m for all test cases does not exceed 5⋅105.
第一行包含一个整数 t(1≤t≤5⋅105),表示测试用例的数量。
每个测试用例的第一行包含两个整数 n,m(1≤n≤5⋅105,0≤m≤min(2n(n−1),5⋅105))。
接下来是 m 行,其中第 i 行包含两个整数 li,ri(1≤li,ri≤n,li=ri),描述 Nanako 选择的第 i 个无序对。保证这 m 个无序对互不相同。
保证所有测试用例的 n 之和不超过 5⋅105,且所有测试用例的 m 之和不超过 5⋅105。
输出格式
For each test case, print two permutations p1,p2,…,pn and q1,q2,…,qn such that the score Nezzar gets is maximized.
对于每个测试用例,输出两个排列 p1,p2,…,pn 和 q1,q2,…,qn,使得 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): p1−p2=1−2=−1, q1−q2=3−4=−1, they have the same sign;
- for the second pair (3,4): p3−p4=3−4=−1, q3−q4=1−2=−1, they have the same sign.
As Nezzar does not lose instantly, Nezzar gains the score of 4 as pi=qi for all 1≤i≤4. Obviously, it is the maximum possible score Nezzar can get.
对于第一个测试用例,针对 Nanako 给出的每一对数:
- 对于第一对 (1,2):p1−p2=1−2=−1,q1−q2=3−4=−1,二者符号相同;
- 对于第二对 (3,4):p3−p4=3−4=−1,q3−q4=1−2=−1,二者符号相同。
由于 Nezzar 并未立即失败,且对所有 1≤i≤4 均有 pi=qi,Nezzar 获得分数 4。显然,这是 Nezzar 能获得的最高可能得分。
输入解题思路,AI测评打分。不知道怎么写?