#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; int main() { int n, m; cin >> n >> m; vector a(m); REP(i, m) cin >> a[i], --a[i]; vector> graph(n); REP(_, n - 1) { int u, v; cin >> u >> v; --u; --v; graph[u].emplace_back(v); graph[v].emplace_back(u); } vector>> chi(n); function pre = [&](int par, int ver) { set st; for (int e : graph[ver]) { if (e == par) continue; int d = pre(ver, e); st.emplace(d); chi[ver].emplace_back(d, e); } int res = 0; while (st.count(res) == 1) ++res; return res; }; pre(-1, 0); vector gru(n); function dfs = [&](int par, int ver, int par_val) { if (par_val >= 0) chi[ver].emplace_back(par_val, par); map> mp; for (auto [val, dst] : chi[ver]) mp[val].emplace_back(dst); map children; gru[ver] = 0; while (mp.count(gru[ver]) == 1) { if (mp[gru[ver]].size() == 1) children[mp[gru[ver]][0]] = gru[ver]; ++gru[ver]; } for (int e : graph[ver]) { if (e != par) dfs(ver, e, children.count(e) == 1 ? children[e] : gru[ver]); } }; dfs(-1, 0, -1); int x = 0; REP(i, m) x ^= gru[a[i]]; if (x > 0) { vector visited(n, false); REP(i, m) { if (visited[a[i]]) continue; visited[a[i]] = true; for (auto [val, dst] : chi[a[i]]) { if ((x ^ gru[a[i]] ^ val) == 0) { cout << i + 1 << ' ' << dst + 1 << '\n'; return 0; } } } assert(false); } cout << "-1 -1\n"; return 0; }