#P9054. [集训队互测 2022] 心跳排列图
[集训队互测 2022] 心跳排列图
Background
The distributed files can be found in the attachment.
Problem Description
Note: In this problem, all sequence indices start from .
What does the robot heartbeats look like when arranged into a graph?
You have a competitive programming robot that beats times per minute. The intensity of the -th beat is . Here, is exactly a permutation of .
Let be the sequence obtained by deleting the -th element from sequence , i.e., .
For a sequence with all distinct elements, let be an undirected graph with vertices, numbered . For every pair of positive integers , if for all , we have , then there is an edge between vertex and vertex in . Let be the length of the shortest path from vertex to vertex in , where the length of a path is defined as its number of edges.
Let .
Given a sequence of length , please find any permutation of such that . It is guaranteed that a solution exists.
In some subtasks, the competitive programming robot little G will give you some “hints”. Let . Let be the set of vertices visited by some shortest path from to in . Let be the set of vertices visited by some shortest path from the start vertex to the end vertex in (note: for convenience, the vertex indices in still use the indices from the original graph, see Sample 2). Then little G may additionally tell you all (including ), or may only tell you , or may provide no hints. See the input format for details.
It is guaranteed that the given hints are correct, i.e., there exists a permutation that satisfies all hints.
The distributed files include checker.cpp, which you can use to check whether your output is correct. Usage: ./checker input output output, where input and output are the input file and your output. testlib.h is also provided; please compile the checker with testlib.h placed in the same directory as the checker.
Input Format
The first line contains two positive integers: the subtask number and the number of test cases .
Then follow test cases. Each test case is:
- The first line contains one positive integer .
- The second line contains positive integers .
In particular,
- If , then for each test case, there will be an additional lines. In these lines, the -th line is a binary string of length , where .
- If , then for each test case, there will be a third line containing a binary string of length , where .
Notes:
- Even if your program does not need the hints, when or you still need to read the array .
- For the same input , the valid may not be unique, and thus may also not be unique. Your output is not required to satisfy the constraints given by our ; it will be judged correct as long as it satisfies the constraints of .
Different variables on the same line are separated by a single space.
Output Format
For each test case, output one line with positive integers: the permutation you found.
9 11
4
2 2 1 1
4
2 2 2 2
4
2 1 1 2
7
5 5 4 4 4 5 5
7
1 3 2 2 2 2 4
7
3 3 2 4 4 5 3
8
2 2 3 5 3 3 3 4
8
5 4 4 4 4 6 6 5
8
4 4 4 2 4 4 2 3
9
4 7 5 5 5 5 3 4 4
9
3 4 4 4 4 4 4 4 6
1 2 4 3
2 1 4 3
1 3 2 4
3 1 7 2 6 4 5
3 1 6 4 2 5 7
2 3 1 6 4 7 5
5 6 3 1 7 4 2 8
1 8 2 7 3 5 6 4
6 3 2 7 4 5 1 8
5 8 6 3 7 1 9 2 4
2 9 3 1 8 5 7 6 4
5 1
4
2 2 1 1
1011
0111
1011
1001
1010
1 2 4 3
6 1
4
2 2 1 1
1011
1 2 4 3
Hint
Explanation of Sample 1
Consider the first test case in the sample. One solution is . Then are , , , , respectively. The edges in the four graphs are:
- : . Therefore .
- : . Therefore .
- : . Therefore .
- : . Therefore .
So , which matches the input.
The valid is not unique. For example, is also correct.
Explanation of Sample 2
The permutation in this sample is the same as the first test case in Sample 1, but this sample includes the hints for subtask . Note that when giving , the original indices are still used. For example, after deleting , the vertices on the new shortest path are numbered .
Explanation of Sample 3
The permutation in this sample is the same as the first test case in Sample 1, but this sample includes the hints for subtask .
Constraints
For all testdata: , , .
- Subtask 1 ( points): , .
- Subtask 2 ( points): .
- Subtask 3 ( points): , and it is guaranteed that there exists a solution satisfying .
- Subtask 4 ( points): , and it is guaranteed that there exists a solution satisfying .
- Subtask 5 ( points): , , with hints for all .
- Subtask 6 ( points): , , with a hint for .
- Subtask 7 ( points): , , with test points. The input is generated by picking a random and then computing as the input.
- Subtask 8 ( points): , .
- Subtask 9 ( point): No special constraints.
Translated by ChatGPT 5