#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define X first #define Y second #define pb push_back #define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X)) #define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X)) #define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X)) #define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X)) #define repe(X,Y) for ((X) = 0;(X) < (Y);++(X)) #define peat(X,Y) for (;(X) < (Y);++(X)) #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)),(X).end()) #define Endl endl #define NL <<"\n" using namespace std; using ll=long long; using pii=pair; using pll=pair; template using vv=vector>; template inline bool MX(T &l,const T &r){return l inline bool MN(T &l,const T &r){return l>r?l=r,1:0;} //#undef NUIP #ifdef NUIP #include "../benri.h" #else #define out(args...) #endif #ifdef __cpp_init_captures templatevector table(int n, T v){ return vector(n, v);} template auto table(int n, Args... args){auto val = table(args...); return vector(n, move(val));} #endif const ll MOD=1e9+7; //998244353 int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout<>n; vv g(n); rep(i,n-1){ int a,b; cin>>a>>b; --a; --b; g[a].pb(b); g[b].pb(a); } vector cnt(n); rep(i,n-1){ int a,b; cin>>a>>b; --a; --b; ++cnt[a]; ++cnt[b]; } out(cnt,1); int res=0; vv h(n); { function dfs= [&](int v,int p){ int re=cnt[v]%2; for(int w:g[v])if(w!=p) re+=dfs(w,v); if(re%2){ ++res; out(v,p,re,1); h[v].pb(p); h[p].pb(v); } return re; }; dfs(0,-1); } int len=0; { vector usd(n); function dfs= [&](int v,int p){ MX(usd[v],1); pii re(-1,v); for(int w:h[v])if(w!=p) MX(re,dfs(w,v)); ++re.X; return re; }; rep(v,n)if(MX(usd[v],1)){ pii w=dfs(v,-1); pii l=dfs(w.Y,-1); out(v,w,l,1); MX(len,l.X); } } out(h,len,1); cout<