#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; bitset used; int dfs(int now, int par) { if (mp[now].count(par)) return mp[now][par]; // int par_idx = -1; // if (par != -1) { // if (mp[now].count(par)) par_idx = mp[now][par]; // else { // rep (i, G[now].size()) { // if (G[now][i] == par) { // par_idx = i; // break; // } // } // mp[now][par] = par_idx; // } // } // if (par == -1) { // if (grundy2[now] != -1) return grundy2[now]; // } // else { // if (grundy[now][par_idx] != -1) return grundy[now][par_idx]; // } 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[v] = true; for (int i = 0; i <= N; i++) { if (not used[i]) { // if (par == -1) grundy2[now] = i; // else grundy[now][par_idx] = i; mp[now][par] = i; for (int v: temp) used[v] = false; 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) { // 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 = mp[v][a[i]]; if ((x ^ y ^ z) == 0) { cout << i + 1 << " " << v + 1 << endl; return 0; } } } }