#include<bits/stdc++.h>
using namespace std;
using ii = pair < int , int >;
const int N = 1e5 + 5;
int n;
int s , d;
int code (int x){ return x + n + 1; }
int decode(int x){ return x - n - 1; }
int low[N] , dfn[N];
int timer = 0 , bcc_count = 0;
int parent[N];
bool cut[N];
vector < int > adj[N] , Tree[N];
set < int > BCC[N];
set < int > belong[N];
set < int > ans;
vector < ii > edges_stack;
/// find bi-connected components /////////////////////////////////
void make_BCC(int u , int v){
if(edges_stack.size() == 0)return;
bcc_count ++;
ii E = {u , v};
while( !edges_stack.empty() ){
ii E2 = edges_stack.back(); edges_stack.pop_back();
int x = E2.first;
int y = E2.second;
BCC[bcc_count].insert(x);
BCC[bcc_count].insert(y);
belong[x].insert(bcc_count);
belong[y].insert(bcc_count);
if(E2 == E)break;
}
}
void dfs(int u , int p){
dfn[u] = low[u] = ++ timer;
int children = 0;
for(int v : adj[u]){
if(dfn[v] == 0){
children ++;
edges_stack.push_back({u , v});
dfs(v , u);
low[u] = min(low[u] , low[v]);
if( (p == -1 && children > 1) || (p != -1 && dfn[u] <= low[v]) ){
cut[u] = 1;
make_BCC(u , v);
}
}
else if(v != p){
if(dfn[v] < low[u]){
low[u] = dfn[v];
edges_stack.push_back({u , v});
}
}
}
}
/// ///////////////////////////////////////////////////////////
/// build bi-connected components Tree ////////////////////////
/// connect each cut point to all component it belongs to
void build_BCC_Tree(){
for(int i = 0 ; i < n ; i ++){
if(cut[i]){
for(int b : belong[i]){
int v = code(b);
Tree[i].push_back(v);
Tree[v].push_back(i);
}
}
}
}
/// ///////////////////////////////////////////////////////////
/// dfs the bi-connected components Tree
void dfs_Tree(int u , int p){
parent[u] = p;
for(int v : Tree[u])if(v != p)dfs_Tree(v , u);
}
main(){
scanf("%d" , &n);
for( ; ; ){
int u , v;
scanf("%d %d" , &u , &v);
if(u == -1 && v == -1)break;
adj[u].push_back(v);
adj[v].push_back(u);
}
scanf("%d %d" , &s , &d);
/// same city
if(s == d){
printf("%d\n" , s);
return 0;
}
for(int i = 0 ; i < n ; i ++){
if(dfn[i] == 0){
dfs(i , -1);
make_BCC(-1 , -1);
}
}
build_BCC_Tree();
/// s is not a cut point so work with its bi-connected component
if(!cut[s])s = code(*(belong[s].begin()));
/// same for d
if(!cut[d])d = code(*(belong[d].begin()));
dfs_Tree(s , -1);
/// now get the path from d to s
while( true ){
/// a cut point
if(d < n)ans.insert(d);
/// a bi-connected component
else {
int comp = decode(d);
for(int B : BCC[comp])ans.insert(B);
}
if(d == s)break;
d = parent[d];
if(d == -1)break;
}
int i = 0;
int sz = ans.size();
for(auto it = ans.begin() ; it != ans.end() ; it ++ , i ++){
printf("%d%s" , *it , i == sz-1 ? "" : " ");
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KIAogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVzaW5nIGlpID0gcGFpciA8IGludCAsIGludCA+OwogCmNvbnN0IGludCBOID0gMWU1ICsgNTsKIAogCmludCBuOwppbnQgcyAsIGQ7CiAKaW50IGNvZGUgIChpbnQgeCl7IHJldHVybiB4ICsgbiArIDE7IH0KaW50IGRlY29kZShpbnQgeCl7IHJldHVybiB4IC0gbiAtIDE7IH0KIAogCmludCBsb3dbTl0gLCBkZm5bTl07CmludCB0aW1lciA9IDAgLCBiY2NfY291bnQgPSAwOwppbnQgcGFyZW50W05dOwpib29sIGN1dFtOXTsKIAogCnZlY3RvciA8IGludCA+IGFkaltOXSAsIFRyZWVbTl07CiAKc2V0IDwgaW50ID4gQkNDW05dOwpzZXQgPCBpbnQgPiBiZWxvbmdbTl07CnNldCA8IGludCA+IGFuczsKIAp2ZWN0b3IgPCBpaSA+IGVkZ2VzX3N0YWNrOwogCi8vLyBmaW5kIGJpLWNvbm5lY3RlZCBjb21wb25lbnRzIC8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLwogCiAKdm9pZCBtYWtlX0JDQyhpbnQgdSAsIGludCB2KXsKICAgIGlmKGVkZ2VzX3N0YWNrLnNpemUoKSA9PSAwKXJldHVybjsKICAgIGJjY19jb3VudCArKzsKIAogICAgaWkgRSA9IHt1ICwgdn07CiAKICAgIHdoaWxlKCAhZWRnZXNfc3RhY2suZW1wdHkoKSApewogICAgICAgIGlpIEUyID0gZWRnZXNfc3RhY2suYmFjaygpOyBlZGdlc19zdGFjay5wb3BfYmFjaygpOwogCiAgICAgICAgaW50IHggPSBFMi5maXJzdDsKICAgICAgICBpbnQgeSA9IEUyLnNlY29uZDsKIAogICAgICAgIEJDQ1tiY2NfY291bnRdLmluc2VydCh4KTsKICAgICAgICBCQ0NbYmNjX2NvdW50XS5pbnNlcnQoeSk7CiAKICAgICAgICBiZWxvbmdbeF0uaW5zZXJ0KGJjY19jb3VudCk7CiAgICAgICAgYmVsb25nW3ldLmluc2VydChiY2NfY291bnQpOwogCiAgICAgICAgaWYoRTIgPT0gRSlicmVhazsKICAgIH0KfQogCnZvaWQgZGZzKGludCB1ICwgaW50IHApewogICAgZGZuW3VdID0gbG93W3VdID0gKysgdGltZXI7CiAgICBpbnQgY2hpbGRyZW4gPSAwOwogCiAgICBmb3IoaW50IHYgOiBhZGpbdV0pewogCiAgICAgICAgaWYoZGZuW3ZdID09IDApewogICAgICAgICAgICBjaGlsZHJlbiArKzsKICAgICAgICAgICAgZWRnZXNfc3RhY2sucHVzaF9iYWNrKHt1ICwgdn0pOwogCiAgICAgICAgICAgIGRmcyh2ICwgdSk7CiAKICAgICAgICAgICAgbG93W3VdID0gbWluKGxvd1t1XSAsIGxvd1t2XSk7CiAKICAgICAgICAgICAgaWYoIChwID09IC0xICYmIGNoaWxkcmVuID4gMSkgfHwgKHAgIT0gLTEgJiYgZGZuW3VdIDw9IGxvd1t2XSkgKXsKICAgICAgICAgICAgICAgIGN1dFt1XSA9IDE7CiAgICAgICAgICAgICAgICBtYWtlX0JDQyh1ICwgdik7CiAgICAgICAgICAgIH0KIAogICAgICAgIH0KICAgICAgICBlbHNlIGlmKHYgIT0gcCl7CiAgICAgICAgICAgIGlmKGRmblt2XSA8IGxvd1t1XSl7CiAgICAgICAgICAgICAgICBsb3dbdV0gPSBkZm5bdl07CiAgICAgICAgICAgICAgICBlZGdlc19zdGFjay5wdXNoX2JhY2soe3UgLCB2fSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KIAovLy8gLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KIAovLy8gYnVpbGQgYmktY29ubmVjdGVkIGNvbXBvbmVudHMgVHJlZSAvLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KIAovLy8gY29ubmVjdCBlYWNoIGN1dCBwb2ludCB0byBhbGwgY29tcG9uZW50IGl0IGJlbG9uZ3MgdG8Kdm9pZCBidWlsZF9CQ0NfVHJlZSgpewogCiAgICBmb3IoaW50IGkgPSAwIDsgaSA8IG4gOyBpICsrKXsKICAgICAgICBpZihjdXRbaV0pewogICAgICAgICAgICBmb3IoaW50IGIgOiBiZWxvbmdbaV0pewogICAgICAgICAgICAgICAgaW50IHYgPSBjb2RlKGIpOwogCiAgICAgICAgICAgICAgICBUcmVlW2ldLnB1c2hfYmFjayh2KTsKICAgICAgICAgICAgICAgIFRyZWVbdl0ucHVzaF9iYWNrKGkpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogCn0KIAovLy8gLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KIAogCi8vLyBkZnMgdGhlIGJpLWNvbm5lY3RlZCBjb21wb25lbnRzIFRyZWUKIAp2b2lkIGRmc19UcmVlKGludCB1ICwgaW50IHApewogICAgcGFyZW50W3VdID0gcDsKIAogICAgZm9yKGludCB2IDogVHJlZVt1XSlpZih2ICE9IHApZGZzX1RyZWUodiAsIHUpOwp9CiAKIAptYWluKCl7CiAgICBzY2FuZigiJWQiICwgJm4pOwogCiAgICBmb3IoIDsgOyApewogICAgICAgIGludCB1ICwgdjsKIAogICAgICAgIHNjYW5mKCIlZCAlZCIgLCAmdSAsICZ2KTsKICAgICAgICBpZih1ID09IC0xICYmIHYgPT0gLTEpYnJlYWs7CiAKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGFkalt2XS5wdXNoX2JhY2sodSk7CiAKICAgIH0KICAgIHNjYW5mKCIlZCAlZCIgLCAmcyAsICZkKTsKIAogICAgLy8vIHNhbWUgY2l0eQogICAgaWYocyA9PSBkKXsKICAgICAgICBwcmludGYoIiVkXG4iICwgcyk7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAKICAgIGZvcihpbnQgaSA9IDAgOyBpIDwgbiA7IGkgKyspewogICAgICAgIGlmKGRmbltpXSA9PSAwKXsKICAgICAgICAgICAgZGZzKGkgLCAtMSk7CiAgICAgICAgICAgIG1ha2VfQkNDKC0xICwgLTEpOwogICAgICAgIH0KICAgIH0KIAogICAgYnVpbGRfQkNDX1RyZWUoKTsKIAogICAgLy8vIHMgaXMgbm90IGEgY3V0IHBvaW50IHNvIHdvcmsgd2l0aCBpdHMgYmktY29ubmVjdGVkIGNvbXBvbmVudAogICAgaWYoIWN1dFtzXSlzID0gY29kZSgqKGJlbG9uZ1tzXS5iZWdpbigpKSk7CiAKICAgIC8vLyBzYW1lIGZvciBkCiAgICBpZighY3V0W2RdKWQgPSBjb2RlKCooYmVsb25nW2RdLmJlZ2luKCkpKTsKIAogICAgZGZzX1RyZWUocyAsIC0xKTsKIAogICAgLy8vIG5vdyBnZXQgdGhlIHBhdGggZnJvbSBkIHRvIHMKICAgIHdoaWxlKCB0cnVlICl7CiAgICAgICAgLy8vIGEgY3V0IHBvaW50CiAgICAgICAgaWYoZCA8IG4pYW5zLmluc2VydChkKTsKIAogICAgICAgIC8vLyBhIGJpLWNvbm5lY3RlZCBjb21wb25lbnQKICAgICAgICBlbHNlIHsKICAgICAgICAgICAgaW50IGNvbXAgPSBkZWNvZGUoZCk7CiAgICAgICAgICAgIGZvcihpbnQgQiA6IEJDQ1tjb21wXSlhbnMuaW5zZXJ0KEIpOwogICAgICAgIH0KICAgICAgICBpZihkID09IHMpYnJlYWs7CiAgICAgICAgZCA9IHBhcmVudFtkXTsKICAgICAgICBpZihkID09IC0xKWJyZWFrOwogICAgfQogCiAgICBpbnQgaSA9IDA7CiAgICBpbnQgc3ogPSBhbnMuc2l6ZSgpOwogICAgZm9yKGF1dG8gaXQgPSBhbnMuYmVnaW4oKSA7IGl0ICE9IGFucy5lbmQoKSA7IGl0ICsrICwgaSArKyl7CiAgICAgICAgcHJpbnRmKCIlZCVzIiAsICppdCAsIGkgPT0gc3otMSA/ICIiIDogIiAiKTsKICAgIH0KIAogICAgcmV0dXJuIDA7Cn0=