All submissions for this problem are available.
FreeKart Company is connected to n cities numbered from 1 to n. Currently the Headquarter of company is situated at index hq1. Each pair of connected cities are connected both ways. The connection is such that there is exactly one connection from the Headquarter to each city. The map of the connected cities is kept in the following way: for each city i, different from the Headquarter, there is kept number ci — index of the last city on the way from the Headquarter to i.
The company decided to move the Headquarter from city hq1 to city hq2. So, after this change the old representation of the map as described above became incorrect. Please, help the company to find out a new map in the way described above.
The first line contains the number of test cases(0 < T <= 10 ). The next line contains three space-separated integers n, hq1, hq2 (2 ≤ n ≤ 2*10^4, 1 ≤ hq1 ≠ hq2 ≤ n) — number of connected cities, index of the old Headquarter and index of the new Headquarter, respectively.
The following line contains n - 1 space-separated integers — the old representation of the map. For each city, other than hq1, there is given integer ci — index of the last city on the way from the Headquarter to city i. All the cities are described in order of increasing indexes.
Output n - 1 numbers — new representation of the map in the same format.
Input 1 3 2 3 2 2 Output 2 3 Input 1 6 2 4 6 1 2 4 2 Output 6 4 1 4 2
|Time Limit:||0.1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions