#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
return 0;
// if the tree has 1 node. the question is already solved.
}
vector<vector<int>> adj(n + 1);
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int root;
cin >> root;
if(adj[root].size() <= 2){
return 0;
// if the root has less than or equal to two nodes it also means that the question is solved.
}
bool found_leaf = false;
for (int i = 1; i <= n; ++i) {
if (adj[i].size() == 1) {
cout << "The leaf node which is now root node: "<< i << endl;
root = i;
found_leaf = true;
break;
}
}
if (!found_leaf) {
cout << "Invalid Tree" << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIGludCBuOyAKICAgIGNpbiA+PiBuOwoKICAgIGlmIChuID09IDEpIHsKICAgICAgICByZXR1cm4gMDsKICAgICAgICAvLyBpZiB0aGUgdHJlZSBoYXMgMSBub2RlLiB0aGUgcXVlc3Rpb24gaXMgYWxyZWFkeSBzb2x2ZWQuCiAgICB9CgogICAgdmVjdG9yPHZlY3RvcjxpbnQ+PiBhZGoobiArIDEpOwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbiAtIDE7ICsraSkgewogICAgICAgIGludCB1LCB2OwogICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgYWRqW3VdLnB1c2hfYmFjayh2KTsKICAgICAgICBhZGpbdl0ucHVzaF9iYWNrKHUpOwogICAgfQoKCWludCByb290OyAKCWNpbiA+PiByb290OwoJCglpZihhZGpbcm9vdF0uc2l6ZSgpIDw9IDIpewoJCXJldHVybiAwOwoJCS8vIGlmIHRoZSByb290IGhhcyBsZXNzIHRoYW4gb3IgZXF1YWwgdG8gdHdvIG5vZGVzIGl0IGFsc28gbWVhbnMgdGhhdCB0aGUgcXVlc3Rpb24gaXMgc29sdmVkLgoJfQoJCgkKICAgIGJvb2wgZm91bmRfbGVhZiA9IGZhbHNlOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgIAogICAgICAgIGlmIChhZGpbaV0uc2l6ZSgpID09IDEpIHsKICAgICAgICAgICAgY291dCA8PCAiVGhlIGxlYWYgbm9kZSB3aGljaCBpcyBub3cgcm9vdCBub2RlOiAiPDwgaSA8PCBlbmRsOwogICAgICAgICAgICByb290ID0gaTsKICAgICAgICAgICAgZm91bmRfbGVhZiA9IHRydWU7CiAgICAgICAgICAgIGJyZWFrOyAKICAgICAgICB9CiAgICB9CgogICAgaWYgKCFmb3VuZF9sZWFmKSB7CiAgICAgICAgY291dCA8PCAiSW52YWxpZCBUcmVlIiA8PCBlbmRsOwogICAgfQoKICAgIHJldHVybiAwOwp9