//#pragma GCC optimize ("-O3","unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v,n) reverse(v,v+n); #define VREVERSE(v) reverse(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define print(x) cout< inline void chmin(T1 & a, T2 b) { if (a > b) a = b; } template inline void chmax(T1& a, T2 b) { if (a < b) a = b; } typedef pairP; const int MOD = 1e9 + 7; const int MAX = 200060; const double pi = acos(-1); const ll INF = 1e18; vectorG1[200020], G2[200020]; int deg[200020]; void solve() { int N; cin >> N; REP(i, N - 1) { int u, v; cin >> u >> v; } REP(i, N - 1) { int u, v; cin >> u >> v; u--, v--; deg[u]++, deg[v]++; } ll ans = N - 1; REP(i,N){ if (deg[i] > 2) { ans += deg[i] - 2; } } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }