Codeforces Beta Round 34(Div. 2)
D
道路地图
Road Map
Codeforces
1600
原题
← CE →

道路地图AI (CI翻译)

There are $*n*$ cities in Berland. Each city has its index — an integer number from $1$ to $*n*$. The capital has index $*r*_{1}$. All the roads in Berland are two-way. The road system is such that there is exactly one path from the capital to each city, i.e. the road map looks like a tree. In Berland's chronicles the road map is kept in the following way: for each city $*i*$, different from the capital, there is kept number $*p*_{*i*}$ — index of the last city on the way from the capital to $*i*$.

在 Berland 有 $*n*$ 座城市。每座城市都有自己的编号——一个从 $1$ 到 $*n*$ 的整数。首都的编号为 $*r*_{1}$。Berland 的所有道路都是双向的。道路系统满足:从首都到每座城市恰好存在一条路径,即道路地图是一棵树。在 Berland 的编年史中,道路地图按如下方式记录:对于每座不同于首都的城市 $*i*$,记录一个数 $*p*_{*i*}$——从首都前往城市 $*i*$ 的途中最后经过的城市的编号。AI (CI翻译)

Once the king of Berland Berl XXXIV decided to move the capital from city $*r*_{1}$ to city $*r*_{2}$. Naturally, after this the old representation of the road map in Berland's chronicles became incorrect. Please, help the king find out a new representation of the road map in the way described above.

有一天,Berland 国王 Berl XXXIV 决定将首都从城市 $*r*_{1}$ 迁移到城市 $*r*_{2}$。自然地,此后 Berland 编年史中原有的道路地图表示就不再正确了。请帮助国王按照上述方式求出道路地图的新表示。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains three space-separated integers $*n*$, $*r*_{1}$, $*r*_{2}$ ($2 ≤ *n* ≤ 5·10^{4}, 1 ≤ *r*_{1} ≠ *r*_{2} ≤ *n*$) — amount of cities in Berland, index of the old capital and index of the new one, correspondingly.

第一行包含三个用空格分隔的整数 $*n*$、$*r*_{1}$ 和 $*r*_{2}$($2 ≤ *n* ≤ 5·10^{4}, 1 ≤ *r*_{1*} ≠ *r*_{2*} ≤ *n*$)——城市数量、原首都编号和新首都编号。AI (CI翻译)

The following line contains $*n* - 1$ space-separated integers — the old representation of the road map. For each city, apart from $*r*_{1}$, there is given integer $*p*_{*i*}$ — index of the last city on the way from the capital to city $*i*$. All the cities are described in order of increasing indexes.

下一行包含 $*n* - 1$ 个用空格分隔的整数——道路地图的原表示。对于除 $*r*_{1}$ 之外的每座城市,给出一个整数 $*p*_{*i*}$——从首都前往城市 $*i*$ 的途中最后经过的城市的编号。所有城市按照编号递增的顺序描述。AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $*n* - 1$ numbers — new representation of the road map in the same format.

输出 $*n* - 1$ 个数——道路地图的新表示,格式与原表示相同。 AI (CI翻译)

样例

Input #1
3 2 3
2 2
Output #1
2 3
InputCopy OutputCopy
Input #2
6 2 4
6 1 2 4 2
Output #2
6 4 1 4 2
InputCopy OutputCopy
题目信息
题号
34D
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。