COROANA TE ROG!!!
#include <fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int n,t[101],p,q;
void schimba(int r) {
if (t[r]!=0) {
schimba(t[r]);
t[t[r]]=r;
}
}
void drum(int v) {
if(v!=0){
drum(t[v]);
g<<v<<" ";
}
}
int main() {
f>>n>>p>>q;
for(int i=1;i<=n;i++)
f>>t[i];
schimba(p);
t[p]=0;
drum(q);
f.close();
g.close();
return 0;
}