#include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<> mp(N); // map mp; vi first_par(N, -1); vii used(N); int dfs(int now, int par) { if (mp[now].count(par)) return mp[now][par]; if (first_par[now] == -1) { first_par[now] = par; vi temp; rep (i, G[now].size()) { int v = G[now][i]; if (v == par) continue; int res = dfs(v, now); temp.push_back(res); } for (int v: temp) used[now][v]++; for (int i = 0; i <= N; i++) { if (used[now][i] == 0) { // if (par == -1) grundy2[now] = i; // else grundy[now][par_idx] = i; mp[now][par] = i; return i; } } } else { int pl = -1; if (first_par[now] != -1) { int pl = dfs(first_par[now], now); } int mi = -1; if (par != -1) { mi = dfs(par, now); } rep (i, N) { int temp = used[now][i]; if (mi == i) temp--; if (pl == i) temp++; if (temp == 0) { mp[now][par] = i; return i; } } } return -1; // ダミー } signed main() { fio(); int n, m; cin >> n >> m; vi a(m); rep (i, m) { cin >> a[i]; a[i]--; } rep (i, n - 1) { int u, v; cin >> u >> v; u--; v--; G[u].push_back(v); G[v].push_back(u); } rep (i, n) { used[i].resize(G[i].size() + 1); } // rep (i, n) { // grundy[i].resize(G[i].size(), -1); // } vector gl; int x = 0; rep (i, m) { gl.push_back(dfs(a[i], -1)); x ^= gl.back(); } if (x == 0) { cout << -1 << " " << -1 << endl; return 0; } rep (i, m) { int y = gl[i]; rep (j, G[a[i]].size()) { int v = G[a[i]][j]; // int par_idx = mp[v][a[i]]; // DEBUG(par_idx); // int z = grundy[v][par_idx]; int z = dfs(v, a[i]); if ((x ^ y ^ z) == 0) { cout << i + 1 << " " << v + 1 << endl; return 0; } } } }