#abc289b. B - V
B - V
Score : points
问题描述
正在学习 汉文 的高桥在理解单词阅读顺序上遇到了困难,快来帮帮他!
有 个从 到 的整数按升序排列成一行。
在这 个整数之间有 个“レ”标记。第 个“レ”标记位于整数 和整数 之间。
按照以下步骤依次读取这 个整数:
- 考虑一个包含 个顶点(编号为 到 )和 条边的无向图 。第 条边连接顶点 和顶点 。
- 重复以下操作,直到没有未读整数:
- 让 为当前最小未读整数。选择包含顶点 的连通分量 ,并按照降序读取该连通分量中所有顶点对应的数字。
例如,假设整数和“レ”标记按照以下顺序排列:
(在这个例子中,,且 。)
那么,读取整数的顺序被确定为 , 和 ,过程如下:
- 首先,最小的未读整数是 ,图 中包含顶点 的连通分量包含顶点 ,因此按照这个顺序读取 和 。
- 然后,最小的未读整数变为 ,图 中包含顶点 的连通分量包含顶点 ,所以按照这个顺序读取 , , 和 。
- 当所有整数都被读取后,终止该过程。
给定 以及 ,输出读取这 个整数的顺序。
什么是连通分量?子图是指从原图中选取部分顶点和边所得到的图形。
若在一个图中,通过边可以到达任意两个顶点,则称该图为 连通 的。
连通分量 是指不包含在任何更大的连通子图内的连通子图。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Studying Kanbun, Takahashi is having trouble figuring out the order to read words. Help him out!
There are integers from through arranged in a line in ascending order.
Between them are "レ" marks. The -th "レ" mark is between the integer and integer .
You read each of the integers once by the following procedure.
- Consider an undirected graph with vertices numbered through and edges. The -th edge connects vertex and vertex .
- Repeat the following operation until there is no unread integer:
- let be the minimum unread integer. Choose the connected component containing vertex , and read all the numbers of the vertices contained in in descending order.
For example, suppose that integers and "レ" marks are arranged in the following order:
(In this case, , and .)
Then, the order to read the integers is determined to be , and , as follows:
- At first, the minimum unread integer is , and the connected component of containing vertex has vertices , so and are read in this order.
- Then, the minimum unread integer is , and the connected component of containing vertex has vertices , so , , and are read in this order.
- Now that all integers are read, terminate the procedure.
Given , and , print the order to read the integers.
What is a connected component? A subgraph of a graph is a graph obtained by choosing some vertices and edges from the original graph.
A graph is said to be connected if and only if one can travel between any two vertices in the graph via edges.
A connected component is a connected subgraph that is not contained in any larger connected subgraph.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in the following format, where is the -th integers to read.
Sample Input 1
5 3
1 3 4
Sample Output 1
2 1 5 4 3
As described in the Problem Statement, if integers and "レ" marks are arranged in the following order:
then the integers are read in the following order: , and .
Sample Input 2
5 0
Sample Output 2
1 2 3 4 5
There may be no "レ" mark.
Sample Input 3
10 6
1 2 3 7 8 9
Sample Output 3
4 3 2 1 5 6 10 9 8 7
update @ 2024/3/10 12:04:10