Problem: There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.

Initially, each edge is painted blue. Takahashi will convert this blue tree into a red tree, by performing the following operation N-1 times:

* Select a simple path that consists of only blue edges, and remove one of those edges.
* Then, span a new red edge between the two endpoints of the selected path.



His objective is to obtain a tree that has a red edge connecting vertices c_i and d_i, for each i.

Determine whether this is achievable.

Constraints

* 2 ≤ N ≤ 10^5
* 1 ≤ a_i,b_i,c_i,d_i ≤ N
* a_i ≠ b_i
* c_i ≠ d_i
* Both input graphs are trees.

Input

Input is given from Standard Input in the following format:


N
a_1 b_1
:
a_{N-1} b_{N-1}
c_1 d_1
:
c_{N-1} d_{N-1}


Output

Print `YES` if the objective is achievable; print `NO` otherwise.

Examples

Input

3
1 2
2 3
1 3
3 2


Output

YES


Input

5
1 2
2 3
3 4
4 5
3 4
2 4
1 4
1 5


Output

YES


Input

6
1 2
3 5
4 6
1 6
5 1
5 3
1 4
2 6
4 3
5 6


Output

NO

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define N 100005
using namespace std;
struct edge{
	int f,t;
	edge(int f1,int t1){
		if(f1>t1) swap(f1,t1);
		f=f1;t=t1;
	}
	bool operator <(const edge &b)const{
		if(f!=b.f) return f<b.f;
		return t<b.t;
	}
};
int bcj[N];
int ff(int x) {return bcj[x]==x? x:bcj[x]=ff(bcj[x]);}
void connect(int fr,int to){
	if(ff(fr)==ff(to)) return ;
	bcj[ff(fr)]=ff(to);
}
vector<int> g1[N],g2[N];
queue<edge> q;
set<edge> st,st2;

int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) bcj[i]=i;
	for(int i=1,f,t;i<n;i++){
		scanf("%d%d",&f,&t);
		st.insert(edge(f,t));
		g1[f].push_back(t),g1[t].push_back(f);
	}
	int cnt=0;
	for(int i=1,f,t;i<n;i++){
		scanf("%d%d",&f,&t);
		edge e(f,t);
		if(st.find(e)!=st.end()) q.push(e);
		else g2[f].push_back(t),g2[t].push_back(f),st2.insert(e);
	}
	while(!q.empty()){
		edge e=q.front();q.pop();
		if(ff(e.f)==ff(e.t)) continue;
		cnt++;
		int f=ff(e.f),t=ff(e.t);
		if(g1[f].size()>g1[t].size()) swap(f,t);
		connect(f,t);
		for(int i=0;i<g1[f].size();i++){
			if(ff(g1[f][i])!=t){
				edge e(ff(g1[f][i]),t);
				if(st2.find(e)!=st2.end()) q.push(e);
				else g1[t].push_back(ff(g1[f][i])),st.insert(e);
			}
		}
		g1[f].clear();
		
		for(int i=0;i<g2[f].size();i++){
			if(ff(g2[f][i])!=t){
				edge e(ff(g2[f][i]),t);
				if(st.find(e)!=st.end()) q.push(e);
				else st2.insert(e),g2[t].push_back(ff(g2[f][i]));
			}
		}
		g2[f].clear();
	}
	
	if(cnt==n-1) puts("YES");
	else puts("NO");
	return 0;
}