import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;

public class D_34 implements Runnable{
    List<Integer> list[];
    int ans[];
    public void solve(){
        int n = scan.nextInt();
        int r1 = scan.nextInt()-1;
        int r2 = scan.nextInt()-1;
        int ar[] = new int[n];
        // ans = new ArrayList<>();
        ans = new int[n];
        list = new List[n];
        for(int i =0;i<n;i++){
            list[i] = new ArrayList<>();
        }
        for(int i=0;i<n;i++){
            if(i!=r1){
                ar[i] = scan.nextInt()-1;
                list[i].add(ar[i]);
                list[ar[i]].add(i);
            }
        }
        dfs(r2,-1);
        for(int i=0;i<n;i++){
            if(i!=r2)
            out.print(ans[i]+ " ");
        }
        return;
    }

    void dfs(int src,int par){
        for(int i : list[src]){
            if(i==par) continue;
            dfs(i,src);
            ans[i] = 1+src;
        }
    }

    InputReader scan;
    PrintWriter out;

    @Override
    public void run(){
        scan = new InputReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null,new D_34(),"Main",1<<26).start();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public long[] nla(int n){ //nextLongArray()
            long ar[] = new long[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextLong();
            }
            return ar;
        }

        public int[] nia(int n){
            int ar[] = new int[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextInt();
            }
            return ar;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}


import javax.print.DocFlavor;
import java.beans.IntrospectionException;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;
public class main implements Runnable {

    static ArrayList<Integer> adj[];

    static void Check2(int n) {
        adj = new ArrayList[n + 1];
        for (int i = 0; i <= n; i++) {
            adj[i] = new ArrayList<>();
        }

    }
    static void add(int i, int j)
    {
        adj[i].add(j);
        adj[j].add(i);
    }
    public static void main(String[] args) {
        new Thread(null, new main(), "Check2", 1 << 28).start();// to increse stack size in java
    }
    static long mod = (long) (1e9 + 7);
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int n=in.nextInt();
        int oldcap=in.nextInt();
        int newcap=in.nextInt();
        Check2(n);
        for(int i=1;i<=n;i++){

            if(i==oldcap)continue;
            add(i,in.nextInt());
        }
        ans=new int[n+1];
        dfs(newcap,new int[n+1],0);

        for(int i=1;i<=n;i++){
            if(i==newcap)continue;
            w.print(ans[i]+" ");
        }

        w.close();

    }

    int ans[];
     void dfs(int i,int v[],int par){

        if(v[i]==1)return;

        v[i]=1;
        ans[i]=par;
        for(Integer ne:adj[i])
        {
            dfs(ne,v,i);
        }

    }
    static class pair2{

        int a;
        int b;
        pair2(int a,int b){
            this.a=a;
            this.b=b;
        }

    }
    static void diji(int s,long dist[],ArrayList <pair> adj[]){
        dist[s]=0;
        PriorityQueue <pair> q=new PriorityQueue<>(new cmp());
        q.add(new pair(s,0));
        while (!q.isEmpty())
        {
            pair p1=q.poll();
            for(pair ne:adj[p1.a]){

                if((long)p1.b+(long)ne.b<dist[ne.a]){
                    dist[ne.a]=(long)p1.b+(long)ne.b;
                    pair p2=new pair(ne.a,dist[ne.a]);
                    q.add(p2);

                }

            }
        }

    }
    static class cmp implements Comparator<pair>{

        public  int compare(pair o1,pair o2)
        {
            return o1.b<o2.b?-1:o1.b>o2.b?1:0;
        }

    }

    static class pair {
        int a;
        long b;
        pair(int a,long b){
            this.a=a;
            this.b=b;
        }
        public boolean equals(Object obj) {      //  override equals method for object to remove tem from arraylist and sets etc.......
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            pair other = (pair) obj;
            if (b!= other.b||a!=other.a)
                return false;
            return true;
        }
    }

    static long modinv(long a,long b)
    {
        long p=power(b,mod-2);

        p=a%mod*p%mod;
        p%=mod;

        return p;

    }

    static long power(long x,long y){
        if(y==0)return 1%mod;
        if(y==1)return x%mod;

        long res=1;
        x=x%mod;
        while(y>0){

            if((y%2)!=0){
                res=(res*x)%mod;
            }

            y=y/2;
            x=(x*x)%mod;
        }

        return res;

    }
    static  int gcd(int a,int b){

        if(b==0)return a;
        return gcd(b,a%b);
    }

    static  void sev(int a[],int n){

        for(int i=2;i<=n;i++)a[i]=i;
        for(int i=2;i<=n;i++){

            if(a[i]!=0){
                for(int j=2*i;j<=n;){

                    a[j]=0;
                    j=j+i;
                }
            }

        }

    }

    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

}


import java.io.*;
import java.util.*;
public final class code
// public class Main
// class code
// public class Solution
{
    static int n,r1,r2;
    static ArrayList<ArrayList<Integer>> list;
    static int a[];
    static void solve()throws IOException
    {
        n=nextInt();
        r1=nextInt();
        r2=nextInt();
        list=new ArrayList<>();
        for(int i=0;i<=n;i++)
            list.add(new ArrayList<Integer>());
        for(int i=1;i<=n;i++)
        {
            if(i!=r1)
            {
                int p=nextInt();
                list.get(p).add(i);
                list.get(i).add(p);
            }
        }
        a=new int[n+1];
        dfs(r2,-1);
        for(int i=1;i<=n;i++)
            if(i!=r2)
                out.print(a[i]+" ");
        out.println();
    }
    static void dfs(int v,int p)
    {
        a[v]=p;
        for(int vv:list.get(v))
        {
            if(vv!=p)
                dfs(vv,v);
        }
    }

    ///////////////////////////////////////////////////////////
    public static void main(String args[])throws IOException
    {
        br=new BufferedReader(new InputStreamReader(System.in));
        out=new PrintWriter(new BufferedOutputStream(System.out));
        random=new Random();

        solve();

        // int t=nextInt();
        // for(int i=1;i<=t;i++)
        // {
        //    out.print("Case #"+i+": ");
        //     solve();
        // }

        out.close();
    }

    static final long mod=(int)(1e9+7);
    static final int inf=(int)(1e9+1);
    // static final long inf=(long)(1e18);

    static class Pair implements Comparable<Pair>
    {
        int first,second;
        Pair(int a,int b)
        {
            first=a;
            second=b;
        }
        public int compareTo(Pair p)
        {
            return first==p.first?second-p.second:first-p.first;
        }
        public boolean equals(Object o)
        {
            Pair p=(Pair)o;
            return first==p.first?second==p.second:false;
        }
        public int hashCode()
        {
            return (int)((1l*first*inf+second)%mod);
        }
        public String toString()
        {
            return first+" "+second;
        }
    }
    static class Triplet implements Comparable<Triplet>
    {
        int first,second,third;
        Triplet(int a,int b,int c)
        {
            first=a;
            second=b;
            third=c;
        }
        public int compareTo(Triplet p)
        {
            return second-p.second;
        }
        public String toString()
        {
            return first+" "+second+" "+third;
        }
    }

    static long modinv(long x)
    {
        return modpow(x,mod-2);
    }
    static long modpow(long a,long b)
    {
        if(b==0)
            return 1;
        long x=modpow(a,b/2);
        x=(x*x)%mod;
        if(b%2==1)
            return (x*a)%mod;
        return x;
    }
    static long gcd(long a,long b)
    {
        if(a==0)
            return b;
        return gcd(b%a,a);
    }
    static int max(int ... a)
    {
    int ret=a[0];
    for(int i=1;i<a.length;i++)
    ret=Math.max(ret,a[i]);
    return ret;
    }
    static int min(int ... a)
    {
    int ret=a[0];
    for(int i=1;i<a.length;i++)
    ret=Math.min(ret,a[i]);
    return ret;
    }
    static void debug(Object ... a)
    {
    System.out.print("> ");
    for(int i=0;i<a.length;i++)
    System.out.print(a[i]+" ");
    System.out.println();
    }
    static void debug(int a[]){debuga(Arrays.stream(a).boxed().toArray());}
    static void debug(long a[]){debuga(Arrays.stream(a).boxed().toArray());}
    static void debuga(Object a[])
    {
    System.out.print("> ");
    for(int i=0;i<a.length;i++)
    System.out.print(a[i]+" ");
    System.out.println();
    }
    static Random random;
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;
    static String nextToken()throws IOException
    {
    while(st==null || !st.hasMoreTokens())
    st=new StringTokenizer(br.readLine());
    return st.nextToken();
    }
    static String nextLine()throws IOException
    {
    return br.readLine();
    }
    static int nextInt()throws IOException
    {
    return Integer.parseInt(nextToken());
    }
    static long nextLong()throws IOException
    {
    return Long.parseLong(nextToken());
    }
    static double nextDouble()throws IOException
    {
    return Double.parseDouble(nextToken());
    }
}


import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class RoadMap {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int numOfCities = scan.nextInt();
		int currentCapital = scan.nextInt() - 1;
		int newCapital = scan.nextInt() - 1;

		LinkedList[] cities = new LinkedList[numOfCities];
		int[] newMap = new int[numOfCities];
		boolean[] visited = new boolean[numOfCities];

		for (int city = 0; city < numOfCities; city++) {
			if (city != currentCapital) {
				int lastOnRoadToCapital = scan.nextInt() - 1;
				if (cities[city] == null) {
					cities[city] = new LinkedList();
				}
				cities[city].addLast(lastOnRoadToCapital);

				if (cities[lastOnRoadToCapital] == null) {
					cities[lastOnRoadToCapital] = new LinkedList();
				}
				cities[lastOnRoadToCapital].addLast(city);
			}
		}

		Stack stack = new Stack();
		stack.push(newCapital);
		visited[newCapital] = true;

		while(true) {
			if (stack.isEmpty()) {
				break;
			}

			int onRoad = (int)stack.pop();

			for (int i = 0; i < cities[onRoad].size(); i++) {
				if (!visited[(int)cities[onRoad].get(i)]) {
					visited[(int)cities[onRoad].get(i)] = true;
					newMap[(int)cities[onRoad].get(i)] = onRoad + 1;
					stack.push(cities[onRoad].get(i));
				}
			}
		}

		for (int j = 0; j < numOfCities; j++) {
			if (newMap[j] != 0)
			System.out.print(newMap[j] + " ");
		}

	}
}


import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class RoadMap {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int numOfCities = scan.nextInt();
		int currentCapital = scan.nextInt() - 1;
		int newCapital = scan.nextInt() - 1;

		LinkedList[] cities = new LinkedList[numOfCities];
		int[] newMap = new int[numOfCities];
		boolean[] visited = new boolean[numOfCities];

		for (int city = 0; city < numOfCities; city++) {

			cities[city] = new LinkedList();
		}

		for (int city = 0; city < numOfCities; city++) {
			if (city != currentCapital) {
				int lastOnRoadToCapital = scan.nextInt() - 1;

				cities[city].addLast(lastOnRoadToCapital);

				cities[lastOnRoadToCapital].addLast(city);
			}
		}

		Stack stack = new Stack();
		stack.push(newCapital);
		visited[newCapital] = true;

		while(true) {
			if (stack.isEmpty()) {
				break;
			}

			int onRoad = (int)stack.pop();

			while (!cities[onRoad].isEmpty()) {

				int index = (int)cities[onRoad].removeFirst();
				if (!visited[index]) {
					visited[index] = true;
					newMap[index] = onRoad + 1;
					stack.push(index);
				}

			}
		}

		for (int j = 0; j < numOfCities; j++) {
			if (newMap[j] != 0)
			System.out.print(newMap[j] + " ");
		}

	}
}


import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class RoadMap {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int numOfCities = scan.nextInt();
		int currentCapital = scan.nextInt() - 1;
		int newCapital = scan.nextInt() - 1;

		LinkedList[] cities = new LinkedList[numOfCities];
		int[] newMap = new int[numOfCities];
		boolean[] visited = new boolean[numOfCities];

		for (int city = 0; city < numOfCities; city++) {

			cities[city] = new LinkedList();
		}

		for (int city = 0; city < numOfCities; city++) {
			if (city != currentCapital) {
				int lastOnRoadToCapital = scan.nextInt() - 1;

				cities[city].addLast(lastOnRoadToCapital);

				cities[lastOnRoadToCapital].addLast(city);
			}
		}

		Stack stack = new Stack();
		stack.push(newCapital);
		visited[newCapital] = true;

		while(true) {
			if (stack.isEmpty()) {
				break;
			}

			int onRoad = (int)stack.pop();

			for (int i = 0; i < cities[onRoad].size(); i++) {
				if (!visited[(int)cities[onRoad].get(i)]) {
					visited[(int)cities[onRoad].get(i)] = true;
					newMap[(int)cities[onRoad].get(i)] = onRoad + 1;
					stack.push(cities[onRoad].get(i));
				}
			}
		}

		for (int j = 0; j < numOfCities; j++) {
			if (newMap[j] != 0)
			System.out.print(newMap[j] + " ");
		}

	}
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alex
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskD {
        void dfs(int cur, int prev, int[] parent, ArrayList<Integer>[] adj) {
            parent[cur] = prev;
            for(int nxt : adj[cur])
                if(nxt != prev) {
                    dfs(nxt, cur, parent, adj);
                }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt(), r1 = in.readInt() - 1, r2 = in.readInt() - 1;
            ArrayList<Integer>[] adj = new ArrayList[n];
            for(int i = 0; i < adj.length; i++) adj[i] = new ArrayList<>();
            for(int i = 0; i < n; i++) {
                if(i == r1) continue;
                int parent = in.readInt() - 1;
                adj[i].add(parent);
                adj[parent].add(i);
            }
            int[] parent = new int[n];
            dfs(r2, -1, parent, adj);
            for(int i = 0; i < parent.length; i++) if(i != r2) out.print((parent[i] + 1) + " ");
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for(int i = 0; i < objects.length; i++) {
                if(i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if(numChars == -1)
                throw new InputMismatchException();
            if(curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch(IOException e) {
                    throw new InputMismatchException();
                }
                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while(isSpaceChar(c))
                c = read();
            int sgn = 1;
            if(c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if(c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while(!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if(filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    static int n,r1,r2;
    //static ArrayList<Integer> g[];
    //static int[] ans;
    //static boolean[] visited;
    static boolean visited[]=new boolean[100010];
    static int ans[]=new int[100010];
  static ArrayList g[]=new ArrayList[100010];
    public static void main(String[] args) throws Exception
    {
        InputStream inputStream = System.in;
        //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         FastReader scn = new FastReader(inputStream);

        PrintWriter pw=new PrintWriter(System.out);
        //StringTokenizer st=new StringTokenizer(br.readLine());
         n=scn.ni();
         r1=scn.ni()-1;;
         r2=scn.ni()-1;
        g=new ArrayList[n];
        ans=new int[n];
        //st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
        if(i!=r1)
        {
            int temp=scn.ni()-1;
            g[i].add(temp);
            g[temp].add(i);

        }
        visited=new boolean[n];
        dfs(r2);
        }
        for(int i=0;i<n;i++)
        {
            if(i==r2)continue;
                pw.print(ans[i]+1+" ");
        }
        pw.close();
    }
    public static void dfs(int current)
    {
        Stack<Integer> s=new Stack<Integer>();
        s.push(current);
        visited[current]=true;
        while(!s.isEmpty())
        {
            int temp=s.pop();
        int size=g[temp].size();
        for(int i=0;i<size;i++)
        {
            int tt=(int)g[temp].get(i);
            //if(tt==parent) continue;
             if(!visited[tt])
            {
                ans[tt]=temp;
                visited[tt]=true;
                s.push(tt);
            }
        }
        }
    }

}
class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return ns ();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    static int n,r1,r2;
    static ArrayList<Integer> g[];
    static int[] ans;
    static boolean[] visited;
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        StringTokenizer st=new StringTokenizer(br.readLine());
         n=Integer.parseInt(st.nextToken());
         r1=Integer.parseInt(st.nextToken())-1;;
         r2=Integer.parseInt(st.nextToken())-1;
        g=new ArrayList[n];
        ans=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
        if(i!=r1)
        {
            int temp=Integer.parseInt(st.nextToken())-1;
            g[i].add(temp);
            g[temp].add(i);

        }
        visited=new boolean[n];
        dfs(r2,-1);
        }
        for(int i=0;i<n;i++)
        {
            if(i!=r2)
            {
                pw.print(ans[i]+1+" ");
            }
        }
        pw.close();
    }
    public static void dfs(int current,int parent)
    {
        int size=g[current].size();
        visited[current]=true;
        for(int i=0;i<size;i++)
        {
            int tt=g[current].get(i);
            if(tt==parent) continue;
            else if(!visited[tt])
            {
                ans[tt]=current;
                dfs(tt,current);
            }
        }
    }

}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    static int n,r1,r2;
    static ArrayList<Integer> g[];
    static int[] ans;
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        StringTokenizer st=new StringTokenizer(br.readLine());
         n=Integer.parseInt(st.nextToken());
         r1=Integer.parseInt(st.nextToken())-1;;
         r2=Integer.parseInt(st.nextToken())-1;
        g=new ArrayList[n];
        ans=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
        if(i!=r1)
        {
            int temp=Integer.parseInt(st.nextToken())-1;
            g[i].add(temp);
            g[temp].add(i);

        }

        }
        dfs(r2,-1);
        for(int i=0;i<n;i++)
        {
            if(i!=r2)
            {
                pw.print(ans[i]+1+" ");
            }
        }
        pw.close();
    }
    public static void dfs(int current,int parent)
    {
        int size=g[current].size();
        for(int i=0;i<size;i++)
        {
            int tt=g[current].get(i);
            if(tt==parent) continue;
            else
            {
                ans[tt]=current;
                dfs(tt,current);
            }
        }
    }

}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    static int n,r1,r2;
    static ArrayList<Integer> g[];
    static int[] ans;
    static boolean[] visited;
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        StringTokenizer st=new StringTokenizer(br.readLine());
         n=Integer.parseInt(st.nextToken());
         r1=Integer.parseInt(st.nextToken())-1;;
         r2=Integer.parseInt(st.nextToken())-1;
        g=new ArrayList[n];
        ans=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
        if(i!=r1)
        {
            int temp=Integer.parseInt(st.nextToken())-1;
            g[i].add(temp);
            g[temp].add(i);

        }
        visited=new boolean[n];
        dfs(r2,-1);
        }
        for(int i=0;i<n;i++)
        {
            if(i!=r2)
            {
                pw.print(ans[i]+1+" ");
            }
        }
        pw.close();
    }
    public static void dfs(int current,int parent)
    {
        Stack<Integer> s=new Stack<Integer>();
        s.push(current);
        visited[current]=true;
        while(!s.isEmpty())
        {
            int temp=s.pop();
        int size=g[temp].size();
        for(int i=0;i<size;i++)
        {
            int tt=g[temp].get(i);
            //if(tt==parent) continue;
             if(!visited[tt])
            {
                ans[tt]=temp;
                visited[tt]=true;
                s.push(tt);
            }
        }
        }
    }

}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    static int n,r1,r2;
    static ArrayList<Integer> g[];
    static int[] ans;
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        StringTokenizer st=new StringTokenizer(br.readLine());
         n=Integer.parseInt(st.nextToken());
         r1=Integer.parseInt(st.nextToken())-1;;
         r2=Integer.parseInt(st.nextToken())-1;
        g=new ArrayList[n];
        ans=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
        if(i!=r1)
        {
            int temp=Integer.parseInt(st.nextToken())-1;
            g[i].add(temp);
            g[temp].add(i);

        }
        dfs(r2,-1);
        }
        for(int i=0;i<n;i++)
        {
            if(i!=r2)
            {
                pw.print(ans[i]+1+" ");
            }
        }
        pw.close();
    }
    public static void dfs(int current,int parent)
    {
        int size=g[current].size();
        for(int i=0;i<size;i++)
        {
            int tt=g[current].get(i);
            if(tt==parent) continue;
            else
            {
                ans[tt]=current;
                dfs(tt,current);
            }
        }
    }

}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    //int n,r1,r2;
    static boolean visited[]=new boolean[100010];
    static int ans[]=new int[100010];
  static ArrayList g[]=new ArrayList[100010];
    public static void main(String[] args) throws Exception
    {
        InputStream inputStream = System.in;
         FastReader scn = new FastReader(inputStream);
         OutputStream outputStream = System.out;
        PrintWriter pw=new PrintWriter(outputStream);
        int n=scn.ni();
         int r1=scn.ni()-1;;
         int r2=scn.ni()-1;
        g=new ArrayList[n];
        ans=new int[n];
        //st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
            if(i==r1) continue;
            int temp=scn.ni()-1;
            g[i].add(temp);
            g[temp].add(i);

        }
        dfs(r2);
        for(int i=0;i<n;i++)
        {
            if(i==r2)continue;
                pw.print(ans[i]+1+" ");
        }
        pw.close();
    }
    public static void dfs(int current)
    {
        Stack<Integer> s=new Stack<Integer>();
        s.push(current);
        visited[current]=true;
        while(!s.isEmpty())
        {
            int temp=s.pop();
        int size=g[temp].size();
        for(int i=0;i<size;i++)
        {
            int tt=(int)g[temp].get(i);
            //if(tt==parent) continue;
             if(!visited[tt])
            {
                ans[tt]=temp;
                visited[tt]=true;
                s.push(tt);
            }
        }
        }
    }

}
class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return ns ();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}


//package codeforces;
import java.io.*;
import java.util.*;
public class RoadMap {
    static int n,r1,r2;
    static ArrayList<Integer> g[];
    static int[] ans;
    static boolean[] visited;
    public static void main(String[] args) throws Exception
    {
        InputStream inputStream = System.in;
        //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         FastReader scn = new FastReader(inputStream);

        PrintWriter pw=new PrintWriter(System.out);
        //StringTokenizer st=new StringTokenizer(br.readLine());
         n=scn.ni();
         r1=scn.ni()-1;;
         r2=scn.ni()-1;
        g=new ArrayList[n];
        ans=new int[n];
        //st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            g[i]=new ArrayList<Integer>();

        }
        for(int i=0;i<n;i++)
        {
        if(i!=r1)
        {
            int temp=scn.ni()-1;
            g[i].add(temp);
            g[temp].add(i);

        }
        visited=new boolean[n];
        dfs(r2);
        }
        for(int i=0;i<n;i++)
        {
            if(i==r2)continue;
                pw.print(ans[i]+1+" ");
        }
        pw.close();
    }
    public static void dfs(int current)
    {
        Stack<Integer> s=new Stack<Integer>();
        s.push(current);
        visited[current]=true;
        while(!s.isEmpty())
        {
            int temp=s.pop();
        int size=g[temp].size();
        for(int i=0;i<size;i++)
        {
            int tt=g[temp].get(i);
            //if(tt==parent) continue;
             if(!visited[tt])
            {
                ans[tt]=temp;
                visited[tt]=true;
                s.push(tt);
            }
        }
        }
    }

}
class FastReader
{

    public InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
        {
            throw new InputMismatchException ();
        }
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read (buf);
            } catch (IOException e)
            {
                throw new InputMismatchException ();
            }
            if (numChars <= 0)
            {
                return -1;
            }
        }
        return buf[curChar++];
    }

 public char nc()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

    public int ni()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public long nl()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read ();
        }
        long res = 0;
        do
        {
            if (c < '0' || c > '9')
            {
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

    public String ns()
    {
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        StringBuilder res = new StringBuilder ();
        do
        {
            res.appendCodePoint (c);
            c = read ();
        } while (!isSpaceChar (c));
        return res.toString ();
    }

    public boolean isSpaceChar(int c)
    {
        if (filter != null)
        {
            return filter.isSpaceChar (c);
        }
        return isWhitespace (c);
    }

    public static boolean isWhitespace(int c)
    {
        return c==' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next()
    {
        return ns ();
    }

    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static int[] newRoadMap;
	public static ArrayList<Integer>[] adj;
	public static int[] visited;

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);

		int n = scn.nextInt();
		int r1 = scn.nextInt();
		int r2 = scn.nextInt();

		int[] roadMap = new int[n];

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(i == r1 - 1)
				roadMap[i] = -1;
			else
				roadMap[i] = scn.nextInt();
		}

		adj = new ArrayList[n];
		for(int i = 0 ; i < adj.length ; i++)
			adj[i] = new ArrayList<Integer>();

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(roadMap[i] == -1)
				continue;
			adj[roadMap[i] - 1].add(i);
			adj[i].add(roadMap[i] - 1);
		}

		newRoadMap = new int[n];
		newRoadMap[r2 - 1] = -1;

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			visited = new int[n];
			for(int j = 0 ; j < visited.length ; j++)
				visited[j] = 0;
			dfs(r2-1 , i);
		}

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			System.out.print(newRoadMap[i] + " ");
		}

	}

	public static void dfs(int start, int value)
	{
		visited[start] = 1;
		for(int i = 0 ; i < adj[start].size(); i++)
		{
			int temp = adj[start].get(i);
			if(temp == value)
				newRoadMap[value] = start + 1;
			else if(visited[temp] == 0)
				dfs(temp,value);
		}
	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static int[] newRoadMap;
	public static ArrayList<Integer>[] adj;
	public static int[] visited;

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);

		int n = scn.nextInt();
		int r1 = scn.nextInt() - 1;
		int r2 = scn.nextInt() - 1;

		int[] roadMap = new int[n];

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(i == r1)
				roadMap[i] = -1;
			else
				roadMap[i] = scn.nextInt() - 1;
		}

		adj = new ArrayList[n];
		for(int i = 0 ; i < adj.length ; i++)
			adj[i] = new ArrayList<Integer>();

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(roadMap[i] == -1)
				continue;
			adj[roadMap[i]].add(i);
			adj[i].add(roadMap[i]);
		}

		newRoadMap = new int[n];
		newRoadMap[r2] = -1;

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			visited = new int[n];
			dfs(r2, i);
		}

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			System.out.print(newRoadMap[i] + " ");
		}

	}

	public static void dfs(int start, int value)
	{
		visited[start] = 1;
		for(int i = 0 ; i < adj[start].size(); i++)
		{
			int temp = adj[start].get(i);
			if(temp == value)
			{
				newRoadMap[value] = start + 1;
				return;
			}
			else if(visited[temp] == 0)
				dfs(temp,value);
		}
	}

}


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static int[] newRoadMap;
	public static ArrayList<Integer>[] adj;
	public static int[] visited;

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);

		int n = scn.nextInt();
		int r1 = scn.nextInt() - 1;
		int r2 = scn.nextInt() - 1;

		int[] roadMap = new int[n];

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(i == r1)
				roadMap[i] = -1;
			else
				roadMap[i] = scn.nextInt() - 1;
		}

		adj = new ArrayList[n];
		for(int i = 0 ; i < adj.length ; i++)
			adj[i] = new ArrayList<Integer>();

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(roadMap[i] == -1)
				continue;
			adj[roadMap[i]].add(i);
			adj[i].add(roadMap[i]);
		}

		newRoadMap = new int[n];
		newRoadMap[r2] = -1;

//		for(int i = 0 ; i < newRoadMap.length ; i++)
//		{
//			if(newRoadMap[i] == -1)
//				continue;
//			visited = new int[n];
//			dfs(r2, i);
//		}
		visited = new int[n];
		dfs(r2);
		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			System.out.print(newRoadMap[i] + " ");
		}

	}

	public static void dfs(int start)
	{
		visited[start] = 1;
		for(int i = 0 ; i < adj[start].size(); i++)
		{
			int temp = adj[start].get(i);
//			if(temp == value)
//			{
//				newRoadMap[value] = start + 1;
//				return;
//			}
//			else if(visited[temp] == 0)
//				dfs(temp,value);

			if(visited[temp] == 0)
			{
				newRoadMap[temp] = start + 1;
				dfs(temp);
			}
		}
	}
}


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static int[] newRoadMap;
	public static ArrayList<Integer>[] adj;
	public static int[] visited;

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);

		int n = scn.nextInt();
		int r1 = scn.nextInt() - 1;
		int r2 = scn.nextInt() - 1;

		int[] roadMap = new int[n];

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(i == r1)
				roadMap[i] = -1;
			else
				roadMap[i] = scn.nextInt() - 1;
		}

		adj = new ArrayList[n];
		for(int i = 0 ; i < adj.length ; i++)
			adj[i] = new ArrayList<Integer>();

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(roadMap[i] == -1)
				continue;
			adj[roadMap[i]].add(i);
			adj[i].add(roadMap[i]);
		}

		newRoadMap = new int[n];
		newRoadMap[r2] = -1;

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			visited = new int[n];
			bfs(r2, i);
		}

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			System.out.print(newRoadMap[i] + " ");
		}

	}

	public static void dfs(int start, int value)
	{
		visited[start] = 1;
		for(int i = 0 ; i < adj[start].size(); i++)
		{
			int temp = adj[start].get(i);
			if(temp == value)
			{
				newRoadMap[value] = start + 1;
				return;
			}
			else if(visited[temp] == 0)
				dfs(temp,value);
		}
	}

	public static void bfs(int start, int value)
	{
		visited[start] = 1;
		Queue<Integer> q = new LinkedList<>();
		q.add(start);

		while(!q.isEmpty())
		{
			int index = q.remove();
			for(int i = 0 ; i < adj[index].size() ; i++)
			{
				int temp = adj[index].get(i);
				if(temp == value)
				{
					newRoadMap[value] = index + 1;
					return;
				}
				else if(visited[temp] == 0)
					q.add(temp);
			}
		}

	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static int[] newRoadMap;
	public static ArrayList<Integer>[] adj;
	public static int[] visited;

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);

		int n = scn.nextInt();
		int r1 = scn.nextInt();
		int r2 = scn.nextInt();

		int[] roadMap = new int[n];

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(i == r1 - 1)
				roadMap[i] = -1;
			else
				roadMap[i] = scn.nextInt();
		}

		adj = new ArrayList[n];
		for(int i = 0 ; i < adj.length ; i++)
			adj[i] = new ArrayList<Integer>();

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(roadMap[i] == -1)
				continue;
			adj[roadMap[i] - 1].add(i);
			adj[i].add(roadMap[i] - 1);
		}

		newRoadMap = new int[n];
		newRoadMap[r2 - 1] = -1;

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			visited = new int[n];
			dfs(r2-1 , i);
		}

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			System.out.print(newRoadMap[i] + " ");
		}

	}

	public static void dfs(int start, int value)
	{
		visited[start] = 1;
		for(int i = 0 ; i < adj[start].size(); i++)
		{
			int temp = adj[start].get(i);
			if(temp == value)
				newRoadMap[value] = start + 1;
			else if(visited[temp] == 0)
				dfs(temp,value);
		}
	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static int[] newRoadMap;
	public static ArrayList<Integer>[] adj;
	public static int[] visited;

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);

		int n = scn.nextInt();
		int r1 = scn.nextInt() - 1;
		int r2 = scn.nextInt() - 1;

		int[] roadMap = new int[n];

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(i == r1)
				roadMap[i] = -1;
			else
				roadMap[i] = scn.nextInt() - 1;
		}

		adj = new ArrayList[n];
		for(int i = 0 ; i < adj.length ; i++)
			adj[i] = new ArrayList<Integer>();

		for(int i = 0 ; i < roadMap.length ; i++)
		{
			if(roadMap[i] == -1)
				continue;
			adj[roadMap[i]].add(i);
			adj[i].add(roadMap[i]);
		}

		newRoadMap = new int[n];
		newRoadMap[r2] = -1;

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			visited = new int[n];
			dfs(r2 , i);
		}

		for(int i = 0 ; i < newRoadMap.length ; i++)
		{
			if(newRoadMap[i] == -1)
				continue;
			System.out.print(newRoadMap[i] + " ");
		}

	}

	public static void dfs(int start, int value)
	{
		visited[start] = 1;
		for(int i = 0 ; i < adj[start].size(); i++)
		{
			int temp = adj[start].get(i);
			if(temp == value)
				newRoadMap[value] = start + 1;
			else if(visited[temp] == 0)
				dfs(temp,value);
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD
    {
        private int[] p;
        private boolean[] was;
        private IntegerGraph g;

        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int r1 = in.nextInt();
            int r2 = in.nextInt();

            g = new IntegerGraph(n, 1);
            for (int i = 1; i <= n; i++)
            {
                if (i == r1)
                {
                    continue;
                }
                int from = i;
                int to = in.nextInt();
                g.addEdge(from, to, true);
            }
            p = new int[n + 1];
            was = new boolean[n + 1];
            dfs(r2, r2);
            for (int i = 1; i <= n; i++)
            {
                if (i == r2)
                {
                    continue;
                }
                out.print(p[i] + " ");
            }
        }

        private void dfs(int u, int prev)
        {
            p[u] = prev;
            was[u] = true;
            ArrayList<Integer> next = g.internalGraph[u];
            for (int i = 0; i < next.size(); i++)
            {
                int v = next.get(i);
                if (!was[v])
                {
                    p[v] = u;
                    dfs(v, u);
                }
            }
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }

    static class IntegerGraph
    {
        public int V;
        public int startVertex;
        public int endVertex;
        public boolean[] was;
        public ArrayList[] internalGraph;

        public IntegerGraph(int V, int offset)
        {
            this.V = V;
            this.startVertex = offset;
            this.endVertex = offset + V - 1;

            was = new boolean[V + offset];
            internalGraph = new ArrayList[V + offset];
            for (int i = offset; i < V + offset; i++)
            {
                internalGraph[i] = new ArrayList<Integer>();
            }
        }

        public boolean addEdge(int from, int to, boolean bidirectional)
        {
            if (bidirectional)
            {
                internalGraph[to].add(from);
            }
            return internalGraph[from].add(to);
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    int n, r1, r2;
    HashMap<Integer, List<Integer>> map = new HashMap<>();
    int[] visited;

    public void solve() throws IOException{

        n = in.nextInt();
        r1 = in.nextInt();
        r2 = in.nextInt();
        visited = new int[n + 1];

        for(int i = 1; i <= n; i++){
            map.put(i, new ArrayList<>());
        }

        for(int i = 1; i <= n; i++){
            if(i == r1) continue;
            int node = in.nextInt();
            map.get(node).add(i);
            map.get(i).add(node);
        }

        dfs(r2, r2);
        for(int i = 1; i <= n; i++){
            if(i == r2) continue;
            out.print(visited[i] + " ");
        }

        return;
    }

    public void dfs(int node, int prev){

        if(visited[node] != 0) return;
        visited[node] = prev;

        List<Integer> nbrs = map.get(node);
        for(int nbr: nbrs){
            dfs(nbr, node);
        }
        return;
    }

    FastScanner in;
    PrintWriter out;

    static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException {
            if (st == null || !st.hasMoreTokens())
                return br.readLine();
            StringBuilder result = new StringBuilder(st.nextToken());
            while (st.hasMoreTokens()) {
                result.append(" ");
                result.append(st.nextToken());
            }
            return result.toString();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

    }

    void run() throws IOException {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException{
        new Main().run();
    }

    public void printArr(int[] arr){
        for(int i = 0; i < arr.length; i++){
            out.print(arr[i] + " ");
        }
        out.println();
    }

    public long gcd(long a, long b){
        if(a == 0) return b;
        return gcd(b % a, a);
    }

    public boolean isPrime(long num){

        if(num == 0 || num == 1){
            return false;
        }

        for(int i = 2; i * i <= num; i++){
            if(num % i == 0){
                return false;
            }
        }

        return true;
    }

    public class Pair<A, B>{
        public A x;
        public B y;

        Pair(A x, B y){
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!x.equals(pair.x)) return false;
            return y.equals(pair.y);
        }

        @Override
        public int hashCode() {
            int result = x.hashCode();
            result = 31 * result + y.hashCode();
            return result;
        }

    }

    class Tuple{
        int x; int y; int z;
        Tuple(int ix, int iy, int iz){
            x = ix;
            y = iy;
            z = iz;
        }
    }
}


import java.io.*;
import java.util.*;

public class B{
   public static void main(String ars[]){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int r1 = in.nextInt()-1;
        int r2 = in.nextInt()-1;
        int p[] = new int[n];
        int p_new[] = new int[n];
        Arrays.fill(p_new,-2);
        for(int i=0;i<n;i++){
            if(i!=r1){
                p[i] = in.nextInt()-1;
            }
            else
                p[i] = -1;
        }
        int cur=r2;
        while(p[cur]!=-1){
            p_new[p[cur]] = cur;
            cur = p[cur];
        }
        for(int i=0;i<n;i++){
            if(p_new[i]==-2)
                p_new[i] = p[i];
            if(i!=r2)
                System.out.print((p_new[i]+1)+" ");
        }
   }

}


import java.util.ArrayList;
import java.util.Scanner;

public class RoadMap {
	private ArrayList<Integer>[] connections;
	private int[] result;
	private boolean[] visited;

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		RoadMap obj = new RoadMap();
		int n = input.nextInt();
		int R1 = input.nextInt();
		int R2 = input.nextInt();
		obj.visited = new boolean[n + 1];
		int temp;
		obj.result = new int[n + 1];
		obj.connections = new ArrayList[n + 1];
		for (int i = 1; i < n + 1; i++) {
			obj.connections[i] = new ArrayList<Integer>();
		}
		for (int i = 1; i <=n; i++) {
			temp = input.nextInt();
			if (i == R1) {
				i++;
			}
			obj.connections[temp].add(i);
			obj.connections[i].add(temp);
		}
		obj.solve(R2);
		for (int i = 1; i <= n; i++) {
			if (i != R2) {
				System.out.print(obj.result[i] + " ");
			}
		}

	}

	private void solve(int index) {
		visited[index] = true;
		for (int i = 0; i < connections[index].size(); i++) {
			if (!visited[connections[index].get(i)]) {
				result[connections[index].get(i)] = index;
				solve(connections[index].get(i));
			}
		}
	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class RoadMap {
	private ArrayList<Integer>[] connections;
	private int[] result;
	private boolean[] visited;

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		RoadMap obj = new RoadMap();
		int n = input.nextInt();
		int R1 = input.nextInt();
		int R2 = input.nextInt();
		obj.visited = new boolean[n + 1];
		int temp;
		obj.result = new int[n + 1];
		obj.connections = new ArrayList[n + 1];
		for (int i = 1; i < n + 1; i++) {
			obj.connections[i] = new ArrayList<Integer>();
		}

		for (int i = 1; i <= n; i++) {
			if (i != R1) {
				temp = input.nextInt();
				obj.connections[temp].add(i);
				obj.connections[i].add(temp);
			}
		}

		obj.solve(R2);
		for (int i = 1; i <= n; i++) {
			if (i != R2) {
				System.out.print(obj.result[i] + " ");
			}
		}

	}

	private void solve(int index) {
		visited[index] = true;
		for (int i = 0; i < connections[index].size(); i++) {
			if (!visited[connections[index].get(i)]) {
				result[connections[index].get(i)] = index;
				solve(connections[index].get(i));
			}
		}
	}

}


/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code292
{
	public static ArrayList<Integer> adj[];
	public static boolean visited[];
	public static int parent[];

	public static void dfs(int s,int par)
	{
		visited[s] = true;
		parent[s] = par;
		for(int p : adj[s])
		{
			if(!visited[p])
				dfs(p,s);
		}
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int n = in.nextInt();
		int r1 = in.nextInt();
		int r2 = in.nextInt();

		adj = new ArrayList[n+1];
		for(int i=0;i<=n;i++)
			adj[i] = new ArrayList<>();
		visited = new boolean[n+1];
		parent = new int[n+1];

		for(int i=1;i<=n;i++)
		{
			if(i==r1)
				i++;
			int j = in.nextInt();
			adj[i].add(j);
			adj[j].add(i);
		}
		dfs(r2,-1);
		for(int i=1;i<=n;i++)
		{
			if(parent[i]!=-1)
				pw.print(parent[i] + " ");
		}
		pw.flush();
		pw.close();
	}

	static class InputReader
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}

	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static HashSet<Integer> primeFactorization(int n)
	{
		HashSet<Integer> a =new HashSet<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(2*i);j<n;j+=i)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static void extendedEuclid(int A,int B)
	{
		if(B==0)
		{
			d = A;
			p = 1 ;
			q = 0;
		}
		else
		{
			extendedEuclid(B, A%B);
			int temp = p;
			p = q;
			q = temp - (A/B)*q;
		}
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static boolean isPrime(int n)
	{

	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    if (n%2 == 0 || n%3 == 0)
	    	return false;

	    for (int i=5; i*i<=n; i=i+6)
	    {
	        if (n%i == 0 || n%(i+2) == 0)
	           return false;
	    }

	    return true;
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString()
		{
			return x+" "+y;
		}

		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}

		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}


/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code292
{
	public static ArrayList<Integer> adj[];
	public static boolean visited[];
	public static int parent[];

	public static void dfs(int s,int par)
	{
		visited[s] = true;
		parent[s] = par;
		for(int p : adj[s])
		{
			if(!visited[p])
				dfs(p,s);
		}
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int n = in.nextInt();
		int r1 = in.nextInt();
		int r2 = in.nextInt();

		adj = new ArrayList[n+1];
		for(int i=0;i<=n;i++)
			adj[i] = new ArrayList<>();
		visited = new boolean[n+1];
		parent = new int[n+1];

		for(int i=1;i<=n;i++)
		{
			if(i==r1)
				i++;
			if(i>n)
				break;
			int j = in.nextInt();
			adj[i].add(j);
			adj[j].add(i);
		}
		dfs(r2,-1);
		for(int i=1;i<=n;i++)
		{
			if(parent[i]!=-1)
				pw.print(parent[i] + " ");
		}
		pw.flush();
		pw.close();
	}

	static class InputReader
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}

	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static HashSet<Integer> primeFactorization(int n)
	{
		HashSet<Integer> a =new HashSet<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(2*i);j<n;j+=i)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static void extendedEuclid(int A,int B)
	{
		if(B==0)
		{
			d = A;
			p = 1 ;
			q = 0;
		}
		else
		{
			extendedEuclid(B, A%B);
			int temp = p;
			p = q;
			q = temp - (A/B)*q;
		}
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static boolean isPrime(int n)
	{

	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    if (n%2 == 0 || n%3 == 0)
	    	return false;

	    for (int i=5; i*i<=n; i=i+6)
	    {
	        if (n%i == 0 || n%(i+2) == 0)
	           return false;
	    }

	    return true;
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString()
		{
			return x+" "+y;
		}

		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}

		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class RoadMap {

	static int cN;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int cO = scan.nextInt();
		cN = scan.nextInt();
		NodeTree[] nodes = new NodeTree[n];
		for(int i = 0; i < n; i++){
			nodes[i] = new NodeTree(i+1);
		}
		for(int i = 0; i < n; i++){
			if(i == cO-1) continue;
			int j = scan.nextInt()-1;
			nodes[i].connect(nodes[j]);
			nodes[j].connect(nodes[i]);
		}

		for(int i = 0; i < n; i++){
			search(nodes[i], null);
		}

		for(int i = 0; i < n; i++){
			if(i == cN-1) continue;
			System.out.print(nodes[i].next+" ");
		}
	}

	public static boolean search(NodeTree n, NodeTree last){
		if(n.name == cN){
			n.next = cN;
			return true;
		}
		n.check = true;
		for(int i = 0; i < n.connections.size(); i++){
			NodeTree j = n.connections.get(i);
			if(!j.equals(last)){
				if(search(j, n)){
					n.next = j.name;
					return true;
				}
			}
		}
		return false;
	}
}

class NodeTree{

	int name;
	ArrayList<NodeTree> connections;
	int next;
	boolean check;

	public NodeTree(int name){
		this.name = name;
		this.connections = new ArrayList<NodeTree>();
		this.next = -1;
		this.check = false;
	}

	public void connect(NodeTree n){
		this.connections.add(n);
	}

	public boolean equals(NodeTree n){
		if(n == null) return false;
		if(this.name == n.name) return true;
		return false;
	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class RoadMap {

	static int cN;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int cO = scan.nextInt();
		cN = scan.nextInt();
		NodeTree[] nodes = new NodeTree[n];
		for(int i = 0; i < n; i++){
			nodes[i] = new NodeTree(i+1);
		}
		for(int i = 0; i < n; i++){
			if(i == cO-1) continue;
			int j = scan.nextInt()-1;
			nodes[i].connect(nodes[j]);
			nodes[j].connect(nodes[i]);
		}
		int left = -1;
		int right = -1;
		for(int i = 0; i < n; i++){
			if(left == -1 && nodes[i].connections.size() == 1){
				left = i;
			}
			else if(nodes[i].connections.size() == 1){
				right = i;
			}
		}
		search(nodes[left], null);
		search(nodes[right], null);
		/*
		for(int i = 0; i < n; i++){
			System.out.println("Node #"+(i+1));
			for(int j = 0; j < nodes[i].connections.size(); j++){
				System.out.println(nodes[i].connections.get(j).name);
			}
		}
		*/
		for(int i = 0; i < n; i++){
			if(i == cN-1) continue;
//			System.out.println(i);
			System.out.print(nodes[i].next+" ");
		}
	}

	public static void search(NodeTree n, NodeTree last){
		if(n.name == cN){
			n.next = cN;
			return;
		}
		n.check = true;
		for(int i = 0; i < n.connections.size(); i++){
			NodeTree j = n.connections.get(i);
			if(!j.equals(last)){
				n.next = j.name;
				search(j, n);
			}
		}
	}
}

class NodeTree{

	int name;
	ArrayList<NodeTree> connections;
	int next;
	boolean check;

	public NodeTree(int name){
		this.name = name;
		this.connections = new ArrayList<NodeTree>();
		this.next = -1;
		this.check = false;
	}

	public void connect(NodeTree n){
		this.connections.add(n);
	}

	public boolean equals(NodeTree n){
		if(n == null) return false;
		if(this.name == n.name) return true;
		return false;
	}
}


import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;

public class RoadMap {

	static int cN;

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		String[] in = br.readLine().split(" ");
		int n = Integer.parseInt(in[0]);
		int cO = Integer.parseInt(in[1]);
		cN = Integer.parseInt(in[2]);
		NodeTree[] nodes = new NodeTree[n];
		for(int i = 0; i < n; i++){
			nodes[i] = new NodeTree(i+1);
		}
		in = br.readLine().split(" ");
//		System.out.println(in.toString());
//		System.out.println(in.length);
		int k = 0;
		for(int i = 0; i < n; i++){
			if(i == cO-1){
				continue;
			}
			int j = Integer.parseInt(in[k])-1;
			nodes[i].connect(nodes[j]);
			nodes[j].connect(nodes[i]);
			k++;
		}
		for(int i = 0; i < n; i++){
			if(nodes[i].next == -1) search(nodes[i], null);
		}
		for(int i = 0; i < n; i++){
			if(i == cN-1) continue;
			out.print(nodes[i].next+" ");
		}
		out.flush();
	}

	public static boolean search(NodeTree n, NodeTree last){
		if(n.name == cN){
			n.next = cN;
			return true;
		}
		n.check = true;
		for(int i = 0; i < n.connections.size(); i++){
			NodeTree j = n.connections.get(i);
			if(!j.equals(last)){
				if(search(j, n)){
					n.next = j.name;
					return true;
				}
			}
		}
		return false;
	}
}

class NodeTree{

	int name;
	ArrayList<NodeTree> connections;
	int next;
	boolean check;

	public NodeTree(int name){
		this.name = name;
		this.connections = new ArrayList<NodeTree>();
		this.next = -1;
		this.check = false;
	}

	public void connect(NodeTree n){
		this.connections.add(n);
	}

	public boolean equals(NodeTree n){
		if(n == null) return false;
		if(this.name == n.name) return true;
		return false;
	}
}


import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;

public class RoadMap {

	static int cN;

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		String[] in = br.readLine().split(" ");
		int n = Integer.parseInt(in[0]);
		int cO = Integer.parseInt(in[1]);
		cN = Integer.parseInt(in[2]);
		NodeTree[] nodes = new NodeTree[n];
		for(int i = 0; i < n; i++){
			nodes[i] = new NodeTree(i+1);
		}
		in = br.readLine().split(" ");
		int k = 0;
		for(int i = 0; i < n; i++){
			if(i == cO-1){
				continue;
			}
			int j = Integer.parseInt(in[k])-1;
			nodes[i].connect(nodes[j]);
			nodes[j].connect(nodes[i]);
			k++;
		}
		search(nodes[cN-1], null);
		for(int i = 0; i < n; i++){
			if(i == cN-1) continue;
			out.print(nodes[i].next+" ");
		}
		out.flush();
	}

	public static void search(NodeTree n, NodeTree last){
		n.check = true;
		if(last != null){
			n.next = last.name;
		}
		for(int i = 0; i < n.connections.size(); i++){
			NodeTree j = n.connections.get(i);
			if(!j.check){
				search(j, n);
			}
		}
	}
}

class NodeTree{

	int name;
	ArrayList<NodeTree> connections;
	int next;
	boolean check;

	public NodeTree(int name){
		this.name = name;
		this.connections = new ArrayList<NodeTree>();
		this.next = -1;
		this.check = false;
	}

	public void connect(NodeTree n){
		this.connections.add(n);
	}

	public boolean equals(NodeTree n){
		if(n == null) return false;
		if(this.name == n.name) return true;
		return false;
	}
}


import java.util.Scanner;

public class RoadMap {

    static int n;

    static int[] parentMap;

    static int[] newParentMap;

    static int visited = 1;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        parentMap = new int[n + 1];
        newParentMap = new int[n + 1];

        int root = sc.nextInt();
        parentMap[root] = 0;

        int newRoot = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i != root) {
                parentMap[i] = sc.nextInt();
            } else {
                parentMap[i] = -1;
            }
        }

        newParentMap[newRoot] = -1;
        dfs(newRoot);

        for (int i = 1; i <= n; i++) {
            if (newParentMap[i] != -1) {
                System.out.print(newParentMap[i] + " ");
            }
        }
        System.out.println();
        sc.close();
    }

    static void dfs(Integer vertice) {
        if (visited == n) {
            return;
        }

        for (int i = 1; i <= n; i++) {
            if (parentMap[i] == vertice && newParentMap[i] == 0) {
                newParentMap[i] = vertice;
                visited++;
                dfs(i);
            }
        }
        int predcestor = parentMap[vertice];
        if (predcestor > 0 && newParentMap[predcestor] == 0) {
            newParentMap[predcestor] = vertice;
            visited++;
            dfs(predcestor);
        }
    }

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class RoadMap {

    static int n;

    static int[] parentMap;

    static int[] newParentMap;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        parentMap = new int[n + 1];
        newParentMap = new int[n + 1];

        int root = sc.nextInt();
        parentMap[root] = 0;

        int newRoot = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i != root) {
                parentMap[i] = sc.nextInt();
            } else {
                parentMap[i] = -1;
            }
        }

        newParentMap[newRoot] = -1;
        dfs(Arrays.asList(newRoot));

        for (int i = 1; i <= n; i++) {
            if (newParentMap[i] != -1) {
                System.out.print(newParentMap[i] + " ");
            }
        }
        System.out.println();
        sc.close();
    }

    static void dfs(List<Integer> vertices) {
        if (allAreVisited() || vertices.size() == 0) {
            return;
        }
        for (Integer v : vertices) {
            List<Integer> neighbours = new ArrayList<>();
            for (int i = 1; i <= n; i++) {
                if (parentMap[i] == v && newParentMap[i] == 0) {
                    neighbours.add(i);
                    newParentMap[i] = v;
                }
            }
            int predcestor = parentMap[v];
            if (predcestor > 0 && newParentMap[predcestor] == 0) {
                neighbours.add(predcestor);
                newParentMap[predcestor] = v;
            }
            dfs(neighbours);
        }
    }

    static boolean allAreVisited() {
        for (int i = 1; i <= n; i++) {
            if (newParentMap[i] == 0) {
                return false;
            }
        }
        return true;
    }

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class RoadMap {

    static int n;

    static int[] parentMap;

    static int[] newParentMap;

    static int visited = 1;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        parentMap = new int[n + 1];
        newParentMap = new int[n + 1];

        int root = sc.nextInt();
        parentMap[root] = 0;

        int newRoot = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i != root) {
                parentMap[i] = sc.nextInt();
            } else {
                parentMap[i] = -1;
            }
        }

        newParentMap[newRoot] = -1;
        dfs(Arrays.asList(newRoot));

        for (int i = 1; i <= n; i++) {
            if (newParentMap[i] != -1) {
                System.out.print(newParentMap[i] + " ");
            }
        }
        System.out.println();
        sc.close();
    }

    static void dfs(List<Integer> vertices) {
        if (visited == n || vertices.size() == 0) {
            return;
        }
        for (Integer v : vertices) {
            List<Integer> neighbours = new ArrayList<>();
            for (int i = 1; i <= n; i++) {
                if (parentMap[i] == v && newParentMap[i] == 0) {
                    neighbours.add(i);
                    newParentMap[i] = v;
                    visited++;
                }
            }
            int predcestor = parentMap[v];
            if (predcestor > 0 && newParentMap[predcestor] == 0) {
                neighbours.add(predcestor);
                newParentMap[predcestor] = v;
                visited++;
            }
            dfs(neighbours);
        }
    }

}


import java.util.Scanner;

public class RoadMap {

    static int n;
    static int[] parentMap;
    static int[] newParentMap;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        parentMap = new int[n + 1];
        newParentMap = new int[n + 1];

        int root = sc.nextInt();
        parentMap[root] = 0;

        int newRoot = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i != root) {
                parentMap[i] = sc.nextInt();
            } else {
                parentMap[i] = -1;
            }
        }

        newParentMap[newRoot] = -1;
        dfs(newRoot);

        for (int i = 1; i <= n; i++) {
            if (i != newRoot) {
                System.out.print(newParentMap[i] + " ");
            }
        }
        sc.close();
    }

    static void dfs(int vertice) {
        for (int i = 1; i <= n; i++) {
            if (parentMap[i] == vertice && newParentMap[i] == 0) {
                newParentMap[i] = vertice;
                dfs(i);
            }
        }

        int predcestor = parentMap[vertice];
        if (predcestor > 0 && newParentMap[predcestor] == 0) {
            newParentMap[predcestor] = vertice;
            dfs(predcestor);
        }

    }

}


import java.util.Scanner;

public class RoadMap {

    static int n;
    static int[] parentMap;
    static int[] newParentMap;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        parentMap = new int[n + 1];
        newParentMap = new int[n + 1];

        int root = sc.nextInt();
        parentMap[root] = 0;

        int newRoot = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i != root) {
                parentMap[i] = sc.nextInt();
            } else {
                parentMap[i] = -1;
            }
        }

        long start = System.currentTimeMillis();

        newParentMap[newRoot] = -1;
        dfs(newRoot);

        for (int i = 1; i <= n; i++) {
            if (i != newRoot) {
                System.out.print(newParentMap[i] + " ");
            }
        }
        sc.close();
        System.out.println();
        long end = System.currentTimeMillis();
        System.out.println((end - start) + " ms");
    }

    static void dfs(int vertice) {
        for (int i = 1; i <= n; i++) {
            if (parentMap[i] == vertice && newParentMap[i] == 0) {
                newParentMap[i] = vertice;
                dfs(i);
            }
        }

        int predcestor = parentMap[vertice];
        if (predcestor > 0 && newParentMap[predcestor] == 0) {
            newParentMap[predcestor] = vertice;
            dfs(predcestor);
        }

    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RoadMap {

    static int n;
    static int[] newParentMap;

    static boolean[] visited;
    static List<Integer>[] graph;

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        newParentMap = new int[n + 1];
        visited = new boolean[n + 1];

        graph = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) {
            graph[i] = new ArrayList<Integer>();
        }

        int root = sc.nextInt();
        int newRoot = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            if (i != root) {
                int c = sc.nextInt();
                graph[i].add(c);
                graph[c].add(i);
            }
        }
        sc.close();

        newParentMap[newRoot] = -1;
        dfs(newRoot, -1);

        for (int i = 1; i <= n; i++) {
            if (i != newRoot) {
                System.out.print(newParentMap[i] + " ");
            }
        }
    }

    static void dfs(int vertice, int parent) {
        newParentMap[vertice] = parent;
        for (int i = 1; i <= n; i++) {
            if (graph[i].contains(vertice) && !visited[i]) {
                newParentMap[i] = vertice;
                visited[i] = true;
                dfs(i, vertice);
            }
        }
    }

}


import java.util.Scanner;

public class RoadMap {

    static int n;
    static int[] parentMap;
    static int[] newParentMap;
    static boolean[] visited;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        parentMap = new int[n + 1];
        newParentMap = new int[n + 1];
        visited = new boolean[n + 1];

        int root = sc.nextInt();
        parentMap[root] = 0;

        int newRoot = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i != root) {
                parentMap[i] = sc.nextInt();
            } else {
                parentMap[i] = -1;
            }
        }

        newParentMap[newRoot] = -1;
        dfs(newRoot);

        for (int i = 1; i <= n; i++) {
            if (i != newRoot) {
                System.out.print(newParentMap[i] + " ");
            }
        }
        sc.close();
    }

    static void dfs(int vertice) {
        for (int i = 1; i <= n; i++) {
            if (parentMap[i] == vertice && !visited[i]) {
                newParentMap[i] = vertice;
                visited[i] = true;
                dfs(i);
            }
        }

        int predcestor = parentMap[vertice];
        if (predcestor > 0 && !visited[predcestor]) {
            visited[predcestor] = true;
            newParentMap[predcestor] = vertice;
            dfs(predcestor);
        }

    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RoadMap {

    static int n;
    static int[] newParentMap;

    static boolean[] visited;
    static List<Integer>[] graph;

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        newParentMap = new int[n + 1];
        visited = new boolean[n + 1];

        graph = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) {
            graph[i] = new ArrayList<Integer>();
        }

        int root = sc.nextInt();
        int newRoot = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            if (i != root) {
                int c = sc.nextInt();
                graph[i].add(c);
                graph[c].add(i);
            }
        }
        sc.close();

        dfs(newRoot, -1);

        for (int i = 1; i <= n; i++) {
            if (i != newRoot) {
                System.out.print(newParentMap[i] + " ");
            }
        }
    }

    static void dfs(int vertice, int parent) {
        newParentMap[vertice] = parent;
        visited[vertice] = true;
        for (int i = 0; i < graph[vertice].size(); i++) {
            int x = graph[vertice].get(i);
            if (!visited[x]) {
                dfs(x, vertice);
            }
        }
    }

}