#include using namespace std; void dfs1(vector &dp, vector> &c, int v = 0){ for (int w : c[v]){ dfs1(dp, c, w); if (!dp[w]){ dp[v] = true; } } } void dfs2(vector &dp2, vector &dp, vector &p, vector> &c, int v = 0){ if (v != 0){ if (!dp2[p[v]]){ dp2[v] = true; } } if (!dp2[v]){ int cnt = 0; for (int w : c[v]){ if (!dp[w]){ cnt++; } } for (int w : c[v]){ if (cnt >= 2 || cnt == 1 && dp[w]){ dp2[w] = true; } } } for (int w : c[v]){ dfs2(dp2, dp, p, c, w); } } int main(){ int N, M; cin >> N >> M; vector A(M); for (int i = 0; i < M; i++){ cin >> A[i]; A[i]--; } vector> E(N); for (int i = 0; i < N - 1; i++){ int u, v; cin >> u >> v; u--; v--; E[u].push_back(v); E[v].push_back(u); } vector p(N, -1); vector> c(N); queue Q; Q.push(0); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : E[v]){ if (p[v] != w){ p[w] = v; c[v].push_back(w); Q.push(w); } } } vector dp(N, false); dfs1(dp, c); vector dp2(N, false); dfs2(dp2, dp, p, c); for (int i = 0; i < N; i++){ cout << dp[i] << ' '; } cout << endl; for (int i = 0; i < N; i++){ cout << dp2[i] << ' '; } cout << endl; int cnt = 0; for (int i = 0; i < M; i++){ if (dp[i] || dp2[i]){ cnt++; } } if (cnt % 2 == 0){ cout << -1 << ' ' << -1 << endl; } else { for (int i = 0; i < M; i++){ if (dp[A[i]]){ for (int j : c[A[i]]){ if (!dp[j]){ cout << i + 1 << ' ' << j + 1 << endl; break; } } break; } else if (dp2[A[i]]){ cout << i + 1 << ' ' << p[A[i]] + 1 << endl; break; } } } }