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

public class Abc {
    static ArrayList<Integer> adj[];
    static int par[];
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),r1=sc.nextInt()-1,r2=sc.nextInt()-1;
        adj=new ArrayList[n];
        for (int i=0;i<n;i++){
            adj[i]=new ArrayList<>();
        }
        par=new int[n];
        par[r2]=r2;
        for (int i=0;i<n;i++){
            if (i==r1)continue;
            int a=i,b=sc.nextInt()-1;
            adj[a].add(b);
            adj[b].add(a);
        }
        dfs(r2);
        StringBuilder sb=new StringBuilder();
        for (int i=0;i<n;i++){
            if (i==r2)continue;
            sb.append((par[i]+1)+" ");
        }
        System.out.println(sb);
    }
    static void dfs(int v){
        for (int u:adj[v]){
            if (u!=par[v]) {
                par[u] = v;
                dfs(u);
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Abc {
    static ArrayList<Integer> adj[];
    static int par[];
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),r1=sc.nextInt()-1,r2=sc.nextInt()-1;
        adj=new ArrayList[n];
        for (int i=0;i<n;i++){
            adj[i]=new ArrayList<>();
        }
        par=new int[n];
        for (int i=0;i<n;i++){
            if (i==r1)continue;
            int a=i,b=sc.nextInt()-1;
            adj[a].add(b);
            adj[b].add(a);
        }
        dfs(r2);
        StringBuilder sb=new StringBuilder();
        for (int i=0;i<n;i++){
            if (i==r2)continue;
            sb.append((par[i]+1)+" ");
        }
        System.out.println(sb);
    }
    static void dfs(int v){
        for (int u:adj[v]){
            if (u!=par[v]) {
                par[u] = v;
                dfs(u);
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class D
{
	static ArrayList<Integer> g[];
	static int[] par,vis;
	static int r2;
	public static void main(String[] args) throws IOException
	{
		FastReader f=new FastReader();
		StringBuffer sb=new StringBuffer();

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

		g=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			g[i]=new ArrayList<>();
		par=new int[n+1];
		vis=new int[n+1];

		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
		{
			if(i==r1)
				continue;
			else
				a[i]=f.nextInt();
		}
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0)
				continue;

			g[i].add(a[i]);
			g[a[i]].add(i);
		}

		dfs(r2,-1);

		for(int i=1;i<=n;i++)
		{
			if(par[i]==-1)
				continue;
			sb.append(par[i]+" ");
		}
		System.out.println(sb);
	}

	static void dfs(int n,int p)
	{
		vis[n] = 1;
		par[n]=p;
		for (int child : g[n]) {
			if (vis[child] == 0)
				dfs(child,n);
		}

	}

	static class FastReader
	{
	    BufferedReader br;
	    StringTokenizer st;

	    public FastReader() {
	    	br = new BufferedReader(new
	                 InputStreamReader(System.in));
	    }
	    String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try{
	                st = new StringTokenizer(br.readLine());
	            }
	            catch (IOException  e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    }
	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    String nextLine() {
	        String str = "";
	        try{
	            str = br.readLine();
	        }
	        catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	    }
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class codeforces
{
   static class Student{
       int x,y;
        Student(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
    static int prime[];
    static void sieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.
        int pos=0;
        prime= new int[n+1];
        for(int p = 2; p*p <=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == 0)
            {
                // Update all multiples of p
                prime[p]=p;
                for(int i = p*p; i <= n; i += p)
                    prime[i] = p;
            }
        }
    }
static    class Sortbyroll implements Comparator<Student>
{
    // Used for sorting in ascending order of
    // roll number
    public int compare(Student c, Student b)
    {
        return c.x-b.x;
    }
}
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    static class Edge{
        int a,b;
        Edge(int a,int b){
            this.a=a;
            this.b=b;
        }
    }
    static int parent[];
    static int rank[];
    public static void main(String[] args){
        //long sum=0;
        FastReader sc=new FastReader();
		int n,b,i,y,x,pre,temp;
		n=sc.nextInt();
		y=sc.nextInt();
		b=sc.nextInt();
		int a[]=new int[n+1];
		i=1;
		while(i<=n){
			if(i==y)
			{
				++i;
				continue;
			}
			a[i]=sc.nextInt();
			++i;
		}
		a[y]=y;
		x=b;
		pre=b;
		while(a[x]!=x){
			temp=a[x];
			a[x]=pre;
			pre=x;
			x=temp;
		}
		a[x]=pre;
		for(i=1;i<=n;i++){
			if(i==b)
				continue;
			System.out.print(a[i]+" ");
		}
		System.out.println();
    }
 /*static long power(long x, long y, long p)
{
    long res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if ((y & (long)1)%2!=0)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res%p;
} */
   static int find(int x)
    {
        // Finds the representative of the set
        // that x is an element of
        while(parent[x]!=x)
        {
            // if x is not the parent of itself
            // Then x is not the representative of
            // his set,
            x=parent[x];

            // so we recursively call Find on its parent
            // and move i's node directly under the
            // representative of this set
        }

        return x;
    }
    static void union(int x, int y)
    {
        // Find representatives of two sets
        int xRoot = find(x), yRoot = find(y);

        // Elements are in the same set, no need
        // to unite anything.
        if (xRoot == yRoot)
            return;

         // If x's rank is less than y's rank
        if (rank[xRoot] < rank[yRoot])

            // Then move x under y  so that depth
            // of tree remains less
            parent[xRoot] = yRoot;

        // Else if y's rank is less than x's rank
        else if (rank[yRoot] < rank[xRoot])

            // Then move y under x so that depth of
            // tree remains less
            parent[yRoot] = xRoot;

        else // if ranks are the same
        {
            // Then move y under x (doesn't matter
            // which one goes where)
            parent[yRoot] = xRoot;

            // And increment the the result tree's
            // rank by 1
            rank[xRoot] = rank[xRoot] + 1;
        }
    }
    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
}


/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    static int parent[];
    static boolean vis[];
    static void dfs(int start,int par){
        vis[start]=true;
        parent[start]=par;
        for(int u:graph[start]){
            if(!vis[u]){
                dfs(u,start);
            }
        }
    }
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        Makegraph(n+1);
        int r1=Integer.parseInt(st[1]);
        int r2=Integer.parseInt(st[2]);
        st=br.readLine().split(" ");
        int j=0;
        for(int i=1;i<=n;i++){
            if(i==r1)i++;
            int a=Integer.parseInt(st[j]);
            addEdge(i,a);
            addEdge(a,i);
            j++;
        }
        vis=new boolean[n+1];
        parent=new int[n+1];
        dfs(r2,r2);
        for(int i=1;i<=n;i++){
            if(i==r2)continue;
            out.print(parent[i]+" ");
        }

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }

/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }

    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}


/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins*****************************************/
    static int parent[];
    static boolean vis[];
    static void dfs(int start,int par){
        vis[start]=true;
        parent[start]=par;
        for(int u:graph[start]){
            if(!vis[u]){
                dfs(u,start);
            }
        }
    }
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        Makegraph(n+1);
        int r1=Integer.parseInt(st[1]);
        int r2=Integer.parseInt(st[2]);
        st=br.readLine().split(" ");
        int j=0;
        for(int i=1;i<=n;i++){
            if(i==r1)i++;
            if(j==n-1)break;
            int a=Integer.parseInt(st[j]);
            addEdge(i,a);
            addEdge(a,i);
            j++;
        }
        vis=new boolean[n+1];
        parent=new int[n+1];
        dfs(r2,r2);
        for(int i=1;i<=n;i++){
            if(i==r2)continue;
            out.print(parent[i]+" ");
        }

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000");
        out.println(ft.format(d));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }

/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }

    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }

            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }

            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }

            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }

            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }
    }
/********************************************End***********************************************************/
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class D {

    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter pw;
	private static int[] ans;
	private static HashSet<Integer>[] hs;
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int cap = nextInt();
        int nextCap = nextInt();
        hs = new HashSet[n+1];
        for (int i = 1; i <= n; i++) {
			hs[i] = new HashSet<Integer>();
		}
        for (int i = 1; i <= n; i++) {
			if(i!=cap){
				int x = nextInt();
				hs[i].add(x);
				hs[x].add(i);
			}
		}
        ans = new int[n+1];
        for (Integer hash : hs[nextCap]) {
			DFS(nextCap,hash);
		}
        for (int i = 1; i <= n; i++) {
        	if(i!=nextCap){
        		System.out.print(ans[i]+" ");
        	}
		}

        pw.close();
    }

    private static void DFS(int oldCity, Integer newCity ) {
    	ans[newCity]=oldCity;
    	for (Integer i : hs[newCity]) {
			if(i==oldCity){
				continue;
			}
    		DFS(newCity,i);
    	}
	}

	private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
    private static String next() throws IOException {
        while (st==null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}


import static java.lang.System.out;
import java.util.*;
import java.io.*;
public class sol_34D {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c1 = sc.nextInt()-1;
		int c2 = sc.nextInt()-1;
		LinkedList<Integer>[] arr = (LinkedList<Integer>[])new LinkedList[n];
		for(int i=0;i<n;i++)
			arr[i] = new LinkedList<Integer>();
		int i=0;
		while(i<n)
		{
			if(i==c1)
				i++;
			else
			{
				int j = sc.nextInt()-1;
				arr[i].add(j);
				arr[j].add(i);
				i++;
			}
		}
		int[] printer = new int[n];
		boolean[] set = new boolean[n];
		set[c2]=true;
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(c2);
		while(!q.isEmpty())
		{
			int x = q.poll();
			for(int y:arr[x])
			{
				if(!set[y])
				{
					set[y] = true;
					printer[y]=x;
					q.add(y);
				}
			}
		}

		for(i=0;i<n;i++)
		{
			if(i!=c2)
			{
				System.out.print(printer[i]+1+" ");
			}
		}

		System.out.println();
	}
}


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

public class D34 {

	public static BufferedReader read = null;
	public static PrintWriter out = null;
	public static StringTokenizer token = null;
	public static int[] p = new int[0];

	public static void dfs(int curr, int parent)
	{
		int np = p[parent];
		p[parent] = curr;
		if(np != parent)
		{
			dfs(parent, np);
		}
	}
	public static void solve()
	{
		int n = nint();
		int r1 = nint();
		int r2 = nint();
		p = new int[n+1];
		p[r1] = r1;
		for(int i=1; i<=n; i++)
		{
			if(i != r1)
			{
				p[i] = nint();
			}

		}

		dfs(r2, p[r2]);

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

	}

	public static void main(String[] args)
	{
		read = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		out.close();

	}

	// i/o functions
	public static String next() // returns the next string
	{
		while(token == null || !token.hasMoreTokens())
		{
			try {
				token = new StringTokenizer(read.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return token.nextToken();
	}

	public static int nint()
	{
		return Integer.parseInt(next());
	}
	public static long nlong()
	{
		return Long.parseLong(next());
	}
	public static double ndouble()
	{
		return Double.parseDouble(next());
	}
	public static int[] narr(int n)
	{
		int[] a = new int[n];
		for(int i=0; i<n; i++) a[i] = nint();
		return a;
	}

	public static long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i=0; i<n; i++) a[i] = nlong();
		return a;
	}

}


import java.io.*;
import java.util.*;
public class gfg{

       static void dfs(LinkedList<Integer> l[],int s,int p,int ar[]){

                           for(Integer i:l[s])
                              if(i!=p){
                                  ar[i]=s+1;
                                  dfs(l,i,s,ar);
                              }
           }

       public static void main(String[] args){
                  PrintWriter out = new PrintWriter(System.out);

                    int n = ni();
                    int r1 = ni();
                    int r2 = ni();

                    LinkedList<Integer> l[] = new LinkedList[n];
                        for(int i=0;i<n;i++)l[i] = new LinkedList();
                    int c=0;
                     for(int i=1;i<=n;i++){
                           int v=ni()-1; c++;
                           if(i==r1)
                                i++;
                           l[i-1].add(v);
                           l[v].add(i-1);
                       if(c==(n-1))
                           break;
                   }
                  int p[] = new int[n];
                  dfs(l,r2-1,-1,p);
               for(int i=0;i<n;i++)
                   if(i!=(r2-1))
                      out.print(p[i]+" ");
                  out.flush();
    }
    static FastReader sc=new FastReader();

      static int ni(){
                 int x = sc.nextInt();
                 return(x);
        }
      static long nl(){
              long x = sc.nextLong();
              return(x);
         }
      static String n(){
                 String str = sc.next();
                     return(str);
       }
     static String ns(){
                 String str = sc.nextLine();
                   return(str);
      }
     static double nd(){
               double d = sc.nextDouble();
                 return(d);
       }
  static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/*
Keep solving problems.
*/

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

public class CFA {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] dx = {0, -1, 0, 1};
    int[] dy = {1, 0, -1, 0};

    List<List<Integer>> graph = new ArrayList<>();
    int[] res;
    void solve() throws IOException {
        int n = nextInt();
        int r1 = nextInt();
        int r2 = nextInt();
        int[] arr = nextIntArr(n - 1);
        res = new int[n];
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 1; i < r1; i++) {
            int u = arr[i - 1] - 1;
            graph.get(i - 1).add(u);
            graph.get(u).add(i - 1);
        }
        for (int i = r1 + 1; i <= n; i++) {
            int u = arr[i - 2] - 1;
            graph.get(i - 1).add(u);
            graph.get(u).add(i - 1);
        }

        r2--;
        dfs(r2, r2);

        for (int i = 0; i < r2; i++) {
            out((1 + res[i]) + " ");
        }
        for (int i = r2 + 1; i < n; i++) {
            out((1 + res[i]) + " ");
        }
    }

    void dfs(int cur, int parent) {
        res[cur] = parent;
        for (int nxt : graph.get(cur)) {
            if (nxt == parent) {
                continue;
            }
            dfs(nxt, cur);
        }
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }

    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


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

public class RoadMap {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        private boolean[] v;
        private int[] p;
        private int[][] g;

        private void dfs(int node) {
            if (v[node]) return;
            v[node] = true;
            for (int n: g[node]) {
                if (v[n]) continue;
                p[n] = node;
                dfs(n);
            }
        }

        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            int r1 = inp.nextInt() - 1;
            int r2 = inp.nextInt() - 1;
            g = new int[n][];
            ArrayList<int[]> edges = new ArrayList<>(n-1);
            int[] neighbours = new int[n];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                int from = inp.nextInt() - 1;
                edges.add(new int[] {from, i});
                neighbours[from]++;
                neighbours[i]++;
            }
            for (int i = 0; i < n; i++) g[i] = new int[neighbours[i]];
            int[] cnt = new int[n];
            for (int[] edge: edges) {
                g[edge[0]][cnt[edge[0]]] = edge[1];
                cnt[edge[0]]++;
                g[edge[1]][cnt[edge[1]]] = edge[0];
                cnt[edge[1]]++;
            }
            /*for (int i = 0; i < n; i++) {
                out.print((i+1) + ":");
                for (int j: g[i]) out.print((j+1) + " ");
                out.print("\n");
            }*/

            v = new boolean[n];
            p = new int[n];
            dfs(r2);
            for (int i = 0; i < p.length; i++) {
                if (i == r2) continue;
                out.print((p[i]+1) + " ");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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


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

public class RoadMap {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        private boolean[] v;
        private int[] p;
        private int[][] g;

        private void dfs(int node) {
            if (v[node]) return;
            v[node] = true;
            for (int n: g[node]) {
                if (v[n]) continue;
                p[n] = node;
                dfs(n);
            }
        }

        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), r1 = inp.nextInt() - 1, r2 = inp.nextInt() - 1;
            v = new boolean[n];
            p = new int[n];
            g = new int[n][];
            int[] cnt = new int[n];
            int[][] edges = new int[n][2];
            int[] neighbours = new int[n];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                edges[i][0] = inp.nextInt() - 1;
                edges[i][1] = i;
                neighbours[edges[i][0]]++;
                neighbours[i]++;
            }
            for (int i = 0; i < n; i++) g[i] = new int[neighbours[i]];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                int[] edge = edges[i];
                g[edge[0]][cnt[edge[0]]++] = edge[1];
                g[edge[1]][cnt[edge[1]]++] = edge[0];
            } dfs(r2);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < p.length; i++) {
                if (i == r2) continue;
                sb.append((p[i]+1));
                sb.append(' ');
            } out.print(sb.toString());
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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


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

public class RoadMap {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        private boolean[] v;
        private int[] p;
        private int[][] g;

        private void dfs(int node) {
            if (v[node]) return;
            v[node] = true;
            for (int n: g[node]) {
                if (v[n]) continue;
                p[n] = node;
                dfs(n);
            }
        }

        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            int r1 = inp.nextInt() - 1;
            int r2 = inp.nextInt() - 1;
            g = new int[n][];
            int[][] edges = new int[n][2];
            //ArrayList<int[]> edges = new ArrayList<>(n-1);
            int[] neighbours = new int[n];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                int from = inp.nextInt() - 1;
                edges[i][0] = from;
                edges[i][1] = i;
                //edges.add(new int[] {from, i});
                neighbours[from]++;
                neighbours[i]++;
            }
            for (int i = 0; i < n; i++) g[i] = new int[neighbours[i]];
            int[] cnt = new int[n];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                int[] edge = edges[i];
                g[edge[0]][cnt[edge[0]]] = edge[1];
                cnt[edge[0]]++;
                g[edge[1]][cnt[edge[1]]] = edge[0];
                cnt[edge[1]]++;
            }

            v = new boolean[n];
            p = new int[n];
            dfs(r2);
            for (int i = 0; i < p.length; i++) {
                if (i == r2) continue;
                out.print((p[i]+1) + " ");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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


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

public class RoadMap {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        private boolean[] v;
        private int[] p;
        private int[][] g;

        private void dfs(int node) {
            if (v[node]) return;
            v[node] = true;
            for (int n: g[node]) {
                if (v[n]) continue;
                p[n] = node;
                dfs(n);
            }
        }

        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), r1 = inp.nextInt() - 1, r2 = inp.nextInt() - 1;
            v = new boolean[n];
            p = new int[n];
            g = new int[n][];
            int[] cnt = new int[n];
            int[][] edges = new int[n][2];
            int[] neighbours = new int[n];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                edges[i][0] = inp.nextInt() - 1;
                edges[i][1] = i;
                neighbours[edges[i][0]]++;
                neighbours[i]++;
            }
            for (int i = 0; i < n; i++) g[i] = new int[neighbours[i]];
            for (int i = 0; i < n; i++) {
                if (i == r1) continue;
                int[] edge = edges[i];
                g[edge[0]][cnt[edge[0]]++] = edge[1];
                g[edge[1]][cnt[edge[1]]++] = edge[0];
            } dfs(r2);
            for (int i = 0; i < p.length; i++) {
                if (i == r2) continue;
                out.print((p[i]+1) + " ");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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


import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.*;
import java.math.*;
public class Main7
{
	static class Pair
	{
		int x;
		int y;
		int z;
		Pair(int x,int y,int z)
		{
			this.x=x;
			this.y=y;
			this.z=z;
		}
	}
	static int mod=1000000007;
	public static int[] sort(int[] a)
	{
		int n=a.length;
		ArrayList<Integer> ar=new ArrayList<>();
		for(int i=0;i<a.length;i++)
		{
			ar.add(a[i]);
		}
		Collections.sort(ar);
		for(int i=0;i<n;i++)
		{
			a[i]=ar.get(i);
		}
		return a;
	}
	public static long pow(long a, long b)
    {
        long result=1;
        while(b>0)
        {
            if (b % 2 != 0)
            {
                result=(result*a)%mod;
                b--;
            }
            a=(a*a)%mod;
            b /= 2;
        }
        return result;
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b%a, a);
    }
	public static long lcm(long a, long b)
	{
		return a*(b/gcd(a,b));
	}
	static ArrayList<ArrayList<Integer>> graph;
	static public void main(String args[])throws IOException
	{
		int tt=1;
		StringBuilder sb1=new StringBuilder();
		for(int ttt=1;ttt<=tt;ttt++)
		{
			int n=i();
			int r1=i()-1;
			int r2=i()-1;
			int[] p=new int[n];
			graph=new ArrayList<>();
			for(int i=0;i<n;i++)
				graph.add(new ArrayList<>());
			for(int i=0;i<n;i++)
			{
				if(i!=r1)
				{
					p[i]=i()-1;
					graph.get(i).add(p[i]);
					graph.get(p[i]).add(i);
				}
			}
			Queue<Integer> queue=new LinkedList<>();
			queue.add(r2);
			boolean[] visited=new boolean[n];
			visited[r2]=true;
			int[] ans=new int[n];
			while(queue.isEmpty()==false)
			{
				int src=queue.poll();
				ArrayList<Integer> ar=graph.get(src);
				for(int i=0;i<ar.size();i++)
				{
					int num=ar.get(i);
					if(visited[num]==false)
					{
						ans[num]=src+1;
						queue.add(num);
						visited[num]=true;
					}
				}
			}
			for(int i=0;i<n;i++)
			{
				if(i!=r2)
					sb1.append(ans[i]+" ");
			}
			sb1.append("\n");
		}
		System.out.print(sb1.toString());
	}
	static int count=0;
	static boolean flag=false;
	static void cycle(int src, boolean[] visited,int parent)
	{
		visited[src]=true;
		ArrayList<Integer> ar=graph.get(src);
		for(int i=0;i<ar.size();i++)
		{
			int num=ar.get(i);
			if(visited[num]==false)
			{
				cycle(num,visited,src);
			}
			else if(visited[num]==true && num!=parent)
			{
				flag=true;
			}
		}
	}
	static void dfs(int src, boolean[] visited)
	{
		visited[src]=true;
		count++;
		ArrayList<Integer> ar=graph.get(src);
		for(int i=0;i<ar.size();i++)
		{
			int num=ar.get(i);
			if(visited[num]==false)
			{
				dfs(num,visited);
			}
		}
	}
	/**/
	static InputReader in=new InputReader(System.in);
	static OutputWriter out=new OutputWriter(System.out);
	public static long l()
	{
		String s=in.String();
		return Long.parseLong(s);
	}
	public static void pln(String value)
	{
		System.out.println(value);
	}
	public static int i()
	{
		return in.Int();
	}
	public static String s()
	{
		return in.String();
	}
}
	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 Int() {
			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 String String() {
			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 String();
		}

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

	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 printLine(Object...objects) {
			print(objects);
			writer.println();
		}

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

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

		}

		class IOUtils {

		public static int[] readIntArray(InputReader in, int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = in.Int();
			return array;
		}

	}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){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 long l(){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 int i(){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 double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //
    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //
    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //
    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //
    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //
    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //
    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //
    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //
    ///////////////////////////////////////////////////////////////////////////////////////////
    static LinkedList<Integer> adj[];
    static int n;
    static int r1;static int r2;
    static int ans[];
    static int mark[];
    public static void dfs(int pos,int par)
    {
        if(mark[pos]==1)
        return;
        mark[pos]=1;
        ans[pos]=par;
        for(int i:adj[pos])
        dfs(i,pos);
    }
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        n=sc.i();
        r1=sc.i();r2=sc.i();
        ans=new int[n];
        adj = new LinkedList[n];
        for (int i=0; i<n; ++i)
        adj[i] = new LinkedList();
        for(int i=0;i<n;i++)
        {
            if(i==r1-1)
            continue;
            int a=sc.i()-1;
            adj[a].add(i);
            adj[i].add(a);
        }
        mark=new int[n];
        dfs(r2-1,r2-1);
        for(int i=0;i<n;i++)
        if(i!=r2-1)
        out.print(ans[i]+1+" ");
        out.flush();
    }
}


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

public class Solution {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    int n, r1, r2;
    ArrayList<Integer>[] g;
    int[] pred;
    boolean[] was;

    void dfs(int v, int p) {
        was[v] = true;
        pred[v] = p;
        for (int i = 0; i < g[v].size(); ++i) {
            int u = g[v].get(i);
            if (!was[u])
                dfs(u, v);
        }
    }

    void solve() throws IOException {
        n = ni();
        r1 = ni() - 1;
        r2 = ni() - 1;
        g = new ArrayList[n];
        for (int i = 0; i < g.length; i++) {
            g[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n; ++i) {
            if (i != r1) {
                int v = ni() - 1;
                g[v].add(i);
                g[i].add(v);
            }
        }
        was = new boolean[n];
        pred = new int[n];
        dfs(r2, -1);
        for (int i = 0; i < n; ++i)
            if (i != r2)
                out.print((pred[i] + 1) + " ");
    }

    public Solution() throws IOException {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

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

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

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


import java.io.*;
import java.util.*;
public class D34
{
    public static void main(String args[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int r1=sc.nextInt();
        int r2=sc.nextInt();
        HashMap<Integer,ArrayList<Integer>> map=new HashMap<>();
        for(int i=1;i<=n;i++)
        {
            map.put(i,new ArrayList<>());
        }
        for(int i=1;i<=n;i++)
        {
            if(i!=r1)
            {
                int num=sc.nextInt();
                map.get(i).add(num);
                map.get(num).add(i);
            }
        }
        int par[]=new int[n+1];
        boolean vis[]=new boolean[n+1];
        Stack st=new Stack();
        st.push(r2);vis[r2]=true;
        while(st.size()!=0)
        {
            int a=(Integer)st.pop();
            for(int j:map.get(a))
            {
                if(!vis[j])
                {
                    vis[j]=true;
                    st.push(j);par[j]=a;
                }
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(par[i]!=0)
                System.out.print(par[i]+" ");
        }
    }
}


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

public class D34 {
    public static void main(String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s1 = inp.readLine().split(" ");
        int vertices = Integer.parseInt(s1[0]);
        int r1 = Integer.parseInt(s1[1]);
        int r2 = Integer.parseInt(s1[2]);
        GraphD34 graph = new GraphD34(vertices);
        String[] s2 = inp.readLine().split(" ");
        int count = 0;
        for(int i=0;i<vertices;i++){
            if(i!=r1-1){
                graph.addEdge(i+1,Integer.parseInt(s2[count]));
                count++;
            }
        }
        graph.DFS(r2);

    }
}
class GraphD34{
    int vertices;
    ArrayList<Integer> edge[];
    static Map<Integer,Integer> parent;
    GraphD34(int vertices){
        this.vertices = vertices;
        edge = new ArrayList[vertices+1];
        parent = new HashMap<>();
        for(int i=0;i<=vertices;i++){
            edge[i] = new ArrayList<>();
        }

    }
    void addEdge(int a,int b){
        edge[a].add(b);
        edge[b].add(a);
    }
    void DFS(int z){
        boolean[] visited = new boolean[vertices+1];
        parent.put(z,z);
        DFSutil(z,visited);
        for(int i=1;i<=vertices;i++){
            if(i!=z){
                System.out.print(parent.get(i)+" ");
            }
        }
    }

    private void DFSutil(int v,boolean[] visited){
        visited[v] = true;
        Iterator<Integer> iterator = edge[v].listIterator();
        while (iterator.hasNext()){
            int n = iterator.next();
            if(!visited[n]){
                parent.put(n,v);
                DFSutil(n,visited);
            }
        }
    }

}


import javafx.scene.layout.Priority;

import java.io.*;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class templ implements Runnable {
    public class pair implements Comparable
    {
        int f,s;
        pair(int f,int s)
        {
            this.f=f;
            this.s=s;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            int ff,ss;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                if((ff==this.f)&&(ss==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
        public int compareTo(Object o)
        {
            pair pr=(pair)o;
            if(s>pr.s)
                return 1;
            else
                return -1;
        }
    }
    ArrayList<Integer>g[];
    int par[];
    int vis[];
    void dfs(int n,int p)
    {
        vis[n]=1;
        par[n]=p;
        for(int i=0;i<g[n].size();i++)
        {
            int v=g[n].get(i);
            if(vis[v]==0)
            {
                dfs(v,n);
            }
        }
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new templ(),"templ",1<<26).start();
    }
    public void run() {
        try {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int n=in.ni();
            int x=in.ni();
            int y=in.ni();
            g=new ArrayList[n+1];
            for(int i=1;i<=n;i++)
                g[i]=new ArrayList<>();
            par=new int[n+1];
            vis=new int[n+1];
            for(int i=1;i<=n;i++)
            {
                if(i==x)
                    continue;
                else
                {
                    int a=in.ni();
                    g[i].add(a);
                    g[a].add(i);
                }
            }
            dfs(y,0);
            for(int i=1;i<=n;i++)
            {
                if(i==y)
                    continue;
                out.print(par[i]+" ");
            }
            out.close();
        }
        catch(Exception e){
            return;
        }
    }
    static class InputReader {

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

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

        public int read() {
            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 ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                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 {
                res *= 10;
                res += c - '0';
                c = read();
            } 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] = ni();
            }
            return a;
        }

        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 String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

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

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

    }
}


//package cdr;
import java.util.*;
import java.math.*;
import java.io.*;

public class Luck{
	public static InputReader sc;
    public static PrintWriter out;
    public static final int MOD = (int) (1e9 + 7);
    static int[] par;
    public static void main(String[] args){
    	sc=new InputReader(System.in);
    	out=new PrintWriter(System.out);
    	int n=sc.nextInt();
    	int r1=sc.nextInt();
    	int r2=sc.nextInt();
    	par=new int[n+1];
    	for(int i=1;i<=n;i++){
    		if(i==r1){
    			par[i]=-1;
    		}
    		else
    			par[i]=sc.nextInt();
    	}
    	int val=r2;
    	int currPar=par[val];

    	while(true){
    		int next=par[currPar];
    		par[currPar]=val;
    		val=currPar;
    		currPar=next;
    		if(next==-1){
    			break;
    		}
    	}
    	par[r2]=-1;
    	for(int i=1;i<=n;i++){
    		if(i!=r2){
    			out.print(par[i]+" ");
    		}
    	}
    	out.close();
    }

    static int gcd(int a,int b){
    	if(b==0){
    		return a;
    	}
    	return gcd(b,a%b);
    }
    static int lcm(int a,int b){
    	int g;
    	if(a<b){
    		g=gcd(b,a);
    	}
    	else{
    		g=gcd(a,b);
    	}
    	return (a*b)/g;
    }

    static boolean isPrime(int n){
    	 if (n == 2)
    	        return true;
    	    for (long i = 2; i * i <= n; i++) {
    	        if (n % i == 0)
    	            return false;
    	    }
    	    return true;
    }

    static void shuffle(int[] A){
    	for(int i=A.length-1;i>0;i--){
    		int j=(int)(Math.random()*(i+1));
    		int temp=A[j];
    		A[j]=A[i];
    		A[i]=temp;
    	}
    }

	public static class Node implements Comparator<Node>{
	    int v;
	    int u;
	    public Node(){
	    	;
	    }
	    public Node (int u, int v) {
	    	this.u = u;
	        this.v = v;

	    }

	    public void print() {
	        out.println(v + " " + u + " ");
	    }

	    public int compare(Node n1,Node n2) {
	        return n1.u-n2.u;
	    }
	}

	public static BigInteger pow(BigInteger base, BigInteger exp) {
	    if(exp.equals(new BigInteger(String.valueOf(0)))){
	        return new BigInteger(String.valueOf(1));
	    }
	    if(exp.equals(new BigInteger(String.valueOf(1))))
	        return base;
	    BigInteger temp=exp.divide(new BigInteger(String.valueOf(2)));
	    BigInteger val = pow(base, temp);
	    BigInteger result = val.multiply(val);
	    result=result.remainder(new BigInteger(String.valueOf(MOD)));
	    BigInteger AND=exp.and(new BigInteger(String.valueOf(1)));
	    if(AND.equals(new BigInteger(String.valueOf(1)))){
	        result = result.multiply(base);
	        result=result.remainder(new BigInteger(String.valueOf(MOD)));
	    }
	    return result;
	}

	static class InputReader {

	    private InputStream stream;
	    private 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 boolean isSpaceChar(int c) {
	        if (filter != null)
	            return filter.isSpaceChar(c);
	        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	    }

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

}


import java.util.*;
public class test
{
    static LinkedList<Integer> adj[];
    static int visited[];
    static int ans[];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        adj=new LinkedList[n+1];
        visited=new int[n+1];
        for(int i=1;i<=n;i++)
            adj[i] = new LinkedList<Integer>();
        int r1 = sc.nextInt();
        int r2 = sc.nextInt();
        int par[]=new int[n+1];
        for(int i=1;i<n+1;i++)
        {
            if(i==r1)
                continue;
            else
            {
                par[i]=sc.nextInt();
                adj[i].add(par[i]);
                adj[par[i]].add(i);
            }
        }
        ans=new int[n+1];
        dfs(r2);
        for(int i=1;i<=n;i++)
            if(i!=r2)
                System.out.print(ans[i]+" ");
        System.out.println();
    }

    static void dfs(int root)
    {
        visited[root]=1;
        for(int child : adj[root])
        {
            if(visited[child]==0)
            {
                ans[child]=root;
                dfs(child);
            }
        }
    }
}


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

public class CF34D {
	static class V {
		int i, p;
		V(int i) {
			this.i = i;
		}
		ArrayList<V> list = new ArrayList<>();
		void dfs(V u) {
			if (u != null)
				p = u.i;
			for (V v : list)
				if (v != u)
					v.dfs(this);
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int r1 = Integer.parseInt(st.nextToken()) - 1;
		int r2 = Integer.parseInt(st.nextToken()) - 1;
		V[] vv = new V[n];
		for (int i = 0; i < n; i++)
			vv[i] = new V(i + 1);
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++)
			if (i != r1) {
				int p = Integer.parseInt(st.nextToken()) - 1;
				vv[p].list.add(vv[i]);
				vv[i].list.add(vv[p]);
			}
		vv[r2].dfs(null);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++)
			if (i != r2)
				sb.append(vv[i].p + " ");
		System.out.println(sb);
	}
}


// package Practice1.CF34;

import java.util.*;

public class CF034D {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int r1 = s.nextInt();
        int r2 = s.nextInt();
//        int[] graph[] = new int[n][n];
        HashMap<Integer,Integer> parent = new HashMap<>();
        HashMap<Integer,ArrayList<Integer>> children = new HashMap<>();

        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            if(i == r1){
                continue;
            }
            int k = s.nextInt();
            arr[i] = k;
            parent.put(i,k);
            ArrayList<Integer> list;
            if(children.containsKey(k)){
                list = children.get(k);
            }else{
                list = new ArrayList<>();
            }
            list.add(i);
            children.put(k,list);
        }

//        System.out.println(parent);
//        System.out.println(children);
        int[] ans = new int[n + 1];
        Queue<Integer> q = new LinkedList<>();
        ((LinkedList<Integer>) q).add(r2);
        while(!q.isEmpty()){
            int km = q.poll();
            ArrayList<Integer> list = children.getOrDefault(km,null);
            if(list != null){
                for (int i = 0; i < list.size(); i++) {
                    ans[list.get(i)] = km;
                }
                q.addAll(list);
            }
        }

        int parent1 = r2;
        int child = parent.get(parent1);
        while(child != r1){
            ans[child] = parent1;
            parent1 = child;
            child = parent.get(parent1);
        }
        ans[child] = parent1;

        for (int i = 1; i <= n; i++) {
            if(ans[i] == 0){
                ans[i] = arr[i];
            }
        }
//        System.out.println(Arrays.toString(ans));
        for (int i = 1; i <= n; i++) {
            if(i == r2){
                continue;
            }
            System.out.print(ans[i] + " ");
        }
    }
}


import java.util.*;

public class P034D {
    private int[] parent1;  // old roadmap
    private int[] parent2;  // new roadmap
    private final int N;
    private final int r1;
    private final int r2;

    private ArrayList<TreeSet<Integer>> neighbors = new ArrayList<TreeSet<Integer>>();

    private void setupTree() {
        for (int i = 0; i < N; i++) {
            if (i == r1) continue;
            int p = parent1[i];

            neighbors.get(i).add(p);
            neighbors.get(p).add(i);
        }
    }

    private void moveRoot() {
        boolean[] visited = new boolean[N];
        java.util.Queue<Integer> queue = new ArrayDeque<Integer>();

        queue.add(r2);
        visited[r2] = true;

        while (!queue.isEmpty()) {
            int u = queue.poll();
            for (int v: neighbors.get(u)) {
                if (!visited[v]) {
                    parent2[v] = u;
                    visited[v] = true;
                    queue.add(v);
                }
            }
        }
    }

    public P034D() {
        Scanner sc = new Scanner(System.in);
        N  = sc.nextInt();
        r1 = sc.nextInt() - 1;
        r2 = sc.nextInt() - 1;
        parent1 = new int[N];
        parent2 = new int[N];

        for (int i = 0; i < N; i++) {
            neighbors.add(new TreeSet<Integer>());
            if (i == r1) continue;
            parent1[i] = sc.nextInt() - 1;
        }

        setupTree();

        moveRoot();

        for (int i = 0; i < N; i++) {
            if (i == r2) continue;
            System.out.printf("%d ", parent2[i] + 1);
        }
    }

    public static void main(String[] args) {
        P034D solution = new P034D();
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Arrays;
import java.util.Vector;
import java.util.Iterator;

public class Main {
        static class MJ{
                static class ArrEl{
                        public static int i, v;
                        ArrEl(){}
                        ArrEl(int index, int value){
                                i = index; v = value;
                        }
                        @SuppressWarnings("static-access")
                        public static ArrEl getMax(int a[]){
                        ArrEl m = new ArrEl(Integer.MIN_VALUE,Integer.MIN_VALUE);
                        for(int i=0; i<a.length; i++)
                                if(a[i]>m.v){m.v=a[i];m.i=i;}
                        return m;
                    }
                        @SuppressWarnings("static-access")
                        public static ArrEl getMin(int a[]){
                        ArrEl m = new ArrEl(Integer.MAX_VALUE,Integer.MAX_VALUE);
                        for(int i=0; i<a.length; i++)
                                if(a[i]<m.v){m.v=a[i];m.i=i;}
                        return m;
                    }
                }
        }
    public static void main(String[] args) throws IOException {
        new Main().run();
    }
    StreamTokenizer in; PrintWriter out; boolean oj; BufferedReader br;

    void init() throws IOException {
        oj = System.getProperty("ONLINE_JUDGE") != null;
        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
        Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
        br = new BufferedReader(reader);
        in = new StreamTokenizer(br);
        out = new PrintWriter(writer);
    }

    void run() throws IOException {
        long beginTime = System.currentTimeMillis();
        init();
        solve();
        if(!oj){
            long endTime = System.currentTimeMillis();
            if (!oj) {
                System.out.println("Memory used = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
                System.out.println("Running time = " + (endTime - beginTime));
            }
        }
        out.flush();
    }
    Vector<Vector<Integer>> V;
        int n, r1, r2, t, L=0, i, d, b[];
    void solve() throws IOException{
        V = new Vector<Vector<Integer>>(); n=nextInt();
        r1=nextInt()-1; r2=nextInt()-1; b = new int[n];
        for(i=0; i<n; i++)V.add(new Vector<Integer>());
        for(i=0; i<n; i++){
                if(i!=r1){
                        t=nextInt()-1;
                        if(t==i)t=r1;
                        V.get(i).add(t);
                        V.get(t).add(i);
                }
        }
        Arrays.fill(b, Integer.MAX_VALUE);
        f(r2,r2);
        for(i=0; i<n; i++)if(i!=r2)out.print(b[i]+" ");
    }

    void f(int x, int l){
        b[x]=l+1;
        Iterator<Integer> I = V.get(x).iterator();
        while(I.hasNext()){
            if(b[t=I.next()]==Integer.MAX_VALUE)
                f(t,x);
        }
    }

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Arrays;
import java.util.Vector;

public class Main {
    static class MJ{
        static class ArrEl{
            public static int i, v;
            ArrEl(){}
            ArrEl(int index, int value){
                i = index; v = value;
            }
            @SuppressWarnings("static-access")
            public static ArrEl getMax(int a[]){
                ArrEl m = new ArrEl(Integer.MIN_VALUE,Integer.MIN_VALUE);
                for(int i=0; i<a.length; i++)
                    if(a[i]>m.v){m.v=a[i];m.i=i;}
                return m;
            }
            @SuppressWarnings("static-access")
            public static ArrEl getMin(int a[]){
                ArrEl m = new ArrEl(Integer.MAX_VALUE,Integer.MAX_VALUE);
                for(int i=0; i<a.length; i++)
                    if(a[i]<m.v){m.v=a[i];m.i=i;}
                return m;
            }
        }
    }
    public static void main(String[] args) throws IOException {
        new Main().run();
    }
    StreamTokenizer in; PrintWriter out; boolean oj; BufferedReader br;

    void init() throws IOException {
        oj = System.getProperty("ONLINE_JUDGE") != null;
        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
        Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
        br = new BufferedReader(reader);
        in = new StreamTokenizer(br);
        out = new PrintWriter(writer);
    }

    void run() throws IOException {
        long beginTime = System.currentTimeMillis();
        init();
        solve();
        if(!oj){
            long endTime = System.currentTimeMillis();
            if (!oj) {
                System.out.println("Memory used = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
                System.out.println("Running time = " + (endTime - beginTime));
            }
        }
        out.flush();
    }
    Vector<Vector<Integer>> V;
    int n, r1, r2, t, L=0, i, d; boolean b[];
    void solve() throws IOException{
        V = new Vector<Vector<Integer>>(); n=nextInt();
        r1=nextInt()-1; r2=nextInt()-1; b=new boolean[n];
        for(i=0; i<n; i++)V.add(new Vector<Integer>());
        for(i=0; i<n; i++){
            if(i!=r1){
                t=nextInt()-1;
                if(t-1==i)t=r1;
                V.get(i).add(t);
                V.get(t).add(i);
            }
        }
        for(i=0; i<n; i++){
            if(i!=r2){
                Arrays.fill(b, true);
                d=i;
                f(r2,r2);
                out.print((L+1)+" ");
            }
        }
    }

    void f(int x, int l){
        if(x==d){L=l;return;}
        b[x]=false;
        for(int j=0; j<n; j++)
            if(V.get(x).contains(j)&b[j])
                f(j,x);
    }

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Arrays;
import java.util.Vector;

public class Main {
    static class MJ{
        static class ArrEl{
            public static int i, v;
            ArrEl(){}
            ArrEl(int index, int value){
                i = index; v = value;
            }
            @SuppressWarnings("static-access")
            public static ArrEl getMax(int a[]){
                ArrEl m = new ArrEl(Integer.MIN_VALUE,Integer.MIN_VALUE);
                for(int i=0; i<a.length; i++)
                    if(a[i]>m.v){m.v=a[i];m.i=i;}
                return m;
            }
            @SuppressWarnings("static-access")
            public static ArrEl getMin(int a[]){
                ArrEl m = new ArrEl(Integer.MAX_VALUE,Integer.MAX_VALUE);
                for(int i=0; i<a.length; i++)
                    if(a[i]<m.v){m.v=a[i];m.i=i;}
                return m;
            }
        }
    }
    public static void main(String[] args) throws IOException {
        new Main().run();
    }
    StreamTokenizer in; PrintWriter out; boolean oj; BufferedReader br;

    void init() throws IOException {
        oj = System.getProperty("ONLINE_JUDGE") != null;
        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
        Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
        br = new BufferedReader(reader);
        in = new StreamTokenizer(br);
        out = new PrintWriter(writer);
    }

    void run() throws IOException {
        long beginTime = System.currentTimeMillis();
        init();
        solve();
        if(!oj){
            long endTime = System.currentTimeMillis();
            if (!oj) {
                System.out.println("Memory used = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
                System.out.println("Running time = " + (endTime - beginTime));
            }
        }
        out.flush();
    }
    Vector<Vector<Integer>> V;
    int n, r1, r2, t, L=0, i, d; String s = ""; boolean b[];
    void solve() throws IOException{
        V = new Vector<Vector<Integer>>(); n=nextInt();
        r1=nextInt()-1; r2=nextInt()-1; b=new boolean[n];
        for(i=0; i<n; i++)V.add(new Vector<Integer>());
        for(i=0; i<n; i++){
            if(i!=r1){
                t=nextInt()-1;
                if(t-1==i)t=r1;
                V.get(i).add(t);
                V.get(t).add(i);
            }
        }
        for(i=0; i<n; i++){
            if(i!=r2){
                Arrays.fill(b, true);
                d=i;
                f(r2,r2);
                s+=(L+1)+" ";
            }
        }
        out.println(s);
    }

    void f(int x, int l){
        if(x==d){L=l;return;}
        b[x]=false;
        for(int j=0; j<n; j++)
            if(V.get(x).contains(j)&b[j])
                f(j,x);
    }

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Arrays;
import java.util.Vector;

public class Main {
	static class MJ{
		static class ArrEl{
			public static int i, v;
			ArrEl(){}
			ArrEl(int index, int value){
				i = index; v = value;
			}
			@SuppressWarnings("static-access")
			public static ArrEl getMax(int a[]){
		    	ArrEl m = new ArrEl(Integer.MIN_VALUE,Integer.MIN_VALUE);
		    	for(int i=0; i<a.length; i++)
		    		if(a[i]>m.v){m.v=a[i];m.i=i;}
		    	return m;
		    }
			@SuppressWarnings("static-access")
			public static ArrEl getMin(int a[]){
		    	ArrEl m = new ArrEl(Integer.MAX_VALUE,Integer.MAX_VALUE);
		    	for(int i=0; i<a.length; i++)
		    		if(a[i]<m.v){m.v=a[i];m.i=i;}
		    	return m;
		    }
		}
	}
    public static void main(String[] args) throws IOException {
        new Main().run();
    }
    StreamTokenizer in; PrintWriter out; boolean oj; BufferedReader br;

    void init() throws IOException {
        oj = System.getProperty("ONLINE_JUDGE") != null;
        Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
        Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
        br = new BufferedReader(reader);
        in = new StreamTokenizer(br);
        out = new PrintWriter(writer);
    }

    void run() throws IOException {
        long beginTime = System.currentTimeMillis();
        init();
        solve();
        if(!oj){
            long endTime = System.currentTimeMillis();
            if (!oj) {
                System.out.println("Memory used = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
                System.out.println("Running time = " + (endTime - beginTime));
            }
        }
        out.flush();
    }
    Vector<Vector<Integer>> V;
	int n, r1, r2, t, L=0, i, d; boolean b[];
    void solve() throws IOException{
    	V = new Vector<Vector<Integer>>(); n=nextInt();
    	r1=nextInt()-1; r2=nextInt()-1; b=new boolean[n];
    	for(i=0; i<n; i++)V.add(new Vector<Integer>());
    	for(i=0; i<n; i++){
    		if(i!=r1){
    			t=nextInt()-1;
    			if(t==i)t=r1;
    			V.get(i).add(t);
    			V.get(t).add(i);
    		}
    	}
    	for(i=0; i<n; i++){
    		if(i!=r2){
    			Arrays.fill(b, true);
    			d=i;
    			f(r2,r2);
    			out.print((L+1)+" ");
    		}
    	}
    }

    void f(int x, int l){
    	if(x==d){L=l;return;}
    	b[x]=false;
    	for(int j=0; j<n; j++)
    		if(V.get(x).contains(j)&b[j])
    			f(j,x);
    }

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	static int[] ans;
	static ArrayList<Integer>[] adj;

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int r1 = in.nextInt();
		int r2 = in.nextInt();
		r1--;
		r2--;
		ans = new int[n];
		adj = new ArrayList[n];
		int f, t;
		for (int i = 0; i < n; i++) {
			if (i == r1)
				continue;
			t = i;
			f = in.nextInt();
			f--;
			if (adj[f] == null)
				adj[f] = new ArrayList<Integer>();
			if (adj[t] == null)
				adj[t] = new ArrayList<Integer>();
			adj[t].add(f);
			adj[f].add(t);
		}
		boolean[] v = new boolean[n];
		dfs(r2, v);
		StringBuilder s = new StringBuilder("");
		for (int i = 0; i < ans.length; i++)
			if (i != r2)
				s.append(" " + (ans[i] + 1));
		System.out.println(s.toString().substring(1));
	}

	public static void dfs(int cur, boolean[] v) {
		if (v[cur])
			return;
		v[cur] = true;
		int s = adj[cur].size();
		for (int i = 0; i < s; i++) {
			if (!v[adj[cur].get(i)]) {
				ans[adj[cur].get(i)] = cur;
				dfs(adj[cur].get(i), v);
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	static int[] ans;
	static ArrayList<Integer>[] adj;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(st.nextToken());
		int r1 = Integer.parseInt(st.nextToken());
		int r2 = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(in.readLine());
		r1--;
		r2--;
		ans = new int[n];
		adj = new ArrayList[n];
		int f, t;
		for (int i = 0; i < n; i++) {
			if (i == r1)
				continue;
			t = i;
			f = Integer.parseInt(st.nextToken());
			f--;
			if (adj[f] == null)
				adj[f] = new ArrayList<Integer>();
			if (adj[t] == null)
				adj[t] = new ArrayList<Integer>();
			adj[t].add(f);
			adj[f].add(t);
		}
		boolean[] v = new boolean[n];
		dfs(r2, v);
		StringBuilder s = new StringBuilder("");
		for (int i = 0; i < ans.length; i++)
			if (i != r2)
				s.append(" " + (ans[i] + 1));
		System.out.println(s.toString().substring(1));
	}

	public static void dfs(int cur, boolean[] v) {
		if (v[cur])
			return;
		v[cur] = true;
		int s = adj[cur].size();
		for (int i = 0; i < s; i++) {
			if (!v[adj[cur].get(i)]) {
				ans[adj[cur].get(i)] = cur;
				dfs(adj[cur].get(i), v);
			}
		}
	}
}


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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author teacher
 */
public class Gorod {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int r1 = in.nextInt();
        int r2 = in.nextInt();
        ArrayList a[] = new ArrayList[n + 1];
        for (int i = 0; i < a.length; i++) {
            a[i] = new ArrayList();
        }
        boolean s[] = new boolean[n + 1];
        int res[] = new int[n + 1];
        ArrayList l = new ArrayList();
        int b[] = new int[2 * n + 2];
        int j = 0;
        int count = 1;
        for (int i = 1; i <= n; i++) {
            if (i != r1) {
                int r = in.nextInt();
                if (i == r2) {
                    res[i] = r2;
                    b[j++] = i;
                    count++;
                }
                if (r == r2) {
                    res[i] = r2;
                    b[j++] = i;
                    count++;
                }
                a[i].add(r);
                a[r].add(i);
            }
        }/*
        for (int i = 1; i < n + 1; i++) {
            Iterator it = a[i].iterator();
            System.out.print(i + "-->");
            while (it.hasNext()) {
                System.out.print((Integer) it.next() + " ");
            }
            System.out.println();
        }*/
        int i = 0;
        s[r2] = true;
        while (count <= n+1) {
            Iterator it = a[b[i]].iterator();
            if(!s[b[i]]){
                s[b[i]]=true;
                count++;
            }
            while (it.hasNext()) {
                int k = (Integer) it.next();
                if (!s[k]) {
                    b[j++] = k;
                    res[k] = b[i];
                }
            }
            i++;
        }
        for (int k = 1;
                k <= n; k++) {
            if (k != r2) {
                System.out.print(res[k] + " ");
            }
        }
    }
}


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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author teacher
 */
public class Gorod {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int r1 = in.nextInt();
        int r2 = in.nextInt();
        ArrayList a[] = new ArrayList[n + 1];
        for (int i = 0; i < a.length; i++) {
            a[i] = new ArrayList();
        }
        boolean s[] = new boolean[n + 1];
        int res[] = new int[n + 1];
        ArrayList l = new ArrayList();
        int b[] = new int[2 * n + 2];
        int j = 0;
        int count = 1;
        for (int i = 1; i <= n; i++) {
            if (i != r1) {
                int r = in.nextInt();
                if (i == r2) {
                    res[i] = r2;
                    b[j++] = i;
                    count++;
                }
                if (r == r2) {
                    res[i] = r2;
                    b[j++] = i;
                    count++;
                }
                a[i].add(r);
                a[r].add(i);
            }
        }/*
        for (int i = 1; i < n + 1; i++) {
            Iterator it = a[i].iterator();
            System.out.print(i + "-->");
            while (it.hasNext()) {
                System.out.print((Integer) it.next() + " ");
            }
            System.out.println();
        }*/
        int i = 0;
        s[r2] = true;
        while (count <= n+1) {
            Iterator it = a[b[i]].iterator();
            while (it.hasNext()) {
                int k = (Integer) it.next();
                if (!s[k]) {
                    b[j++] = k;
                    count++;
                    res[k] = b[i];
                    s[k] = true;
                }
            }
            i++;
        }
        for (int k = 1;
                k <= n; k++) {
            if (k != r2) {
                System.out.print(res[k] + " ");
            }
        }
    }
}