#include using namespace std; const int INF = 1e9; int N; vector G[200000]; int deg[200000]; int dp[200000][3]; void calc(int v, int p){ for(auto to : G[v]){ if(to == p) continue; calc(to, v); deg[v] += deg[to]; int nxt[3] = {INF, INF, INF}; for(int i = 0; i < 3; i++){ for(int j = 0; i + j < 3; j++){ nxt[i + j] = min(nxt[i + j], dp[v][i] + dp[to][j] + !(deg[to] % 2 == j % 2)); } } swap(dp[v], nxt); } } int main(){ cin >> N; for(int i = 0; i < N - 1; i++){ int A, B; cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } for(int i = 0; i < N - 1; i++){ int C, D; cin >> C >> D; C--; D--; deg[C]++; deg[D]++; } calc(0, -1); cout << min(dp[0][0], dp[0][2]) + N - 1 << endl; }