#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int fa[100010],sz[100010];
std::unordered_set<int>stA[100010],stB[100010];
std::queue<std::pair<int,int>>que;
int hd(int x){return fa[x]==x?x:fa[x]=hd(fa[x]);}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),a,b;
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<n;++i){
		a=gi(),b=gi();
		++sz[a],++sz[b];
		stA[a].insert(b);
		stA[b].insert(a);
	}
	for(int i=1;i<n;++i){
		a=gi(),b=gi();
		++sz[a],++sz[b];
		if(stA[a].count(b))que.push({a,b});
		else stB[a].insert(b),stB[b].insert(a);
	}
	for(int i=1;i<n;++i){
		if(que.empty())return puts("NO"),0;
		int a=que.front().first,b=que.front().second,A=hd(a),B=hd(b);que.pop();
		if(A==B){--i;continue;}
		if(sz[A]>sz[B])std::swap(A,B),std::swap(a,b);
		fa[A]=B;sz[B]+=sz[A];
		stA[A].erase(b);stB[A].erase(b);
		stA[B].erase(a);stB[B].erase(a);
		for(int j:stA[A]){
			j=hd(j);
			if(j==A||j==B)continue;
			if(stB[B].count(j))que.push({j,B});
			else{
				stA[j].erase(A);stA[j].insert(B);
				stA[B].insert(j);
			}
		}
		stA[A].clear();
		for(int j:stB[A]){
			j=hd(j);
			if(j==A||j==B)continue;
			if(stA[B].count(j))que.push({j,B});
			else{
				stB[j].erase(A);stB[j].insert(B);
				stB[B].insert(j);
			}
		}
		stB[A].clear();
	}
	return puts("YES"),0;
}

### Prompt

Your task is to create a CPP solution to the following 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

### Response

```cpp
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int fa[100010],sz[100010];
std::unordered_set<int>stA[100010],stB[100010];
std::queue<std::pair<int,int>>que;
int hd(int x){return fa[x]==x?x:fa[x]=hd(fa[x]);}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),a,b;
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<n;++i){
		a=gi(),b=gi();
		++sz[a],++sz[b];
		stA[a].insert(b);
		stA[b].insert(a);
	}
	for(int i=1;i<n;++i){
		a=gi(),b=gi();
		++sz[a],++sz[b];
		if(stA[a].count(b))que.push({a,b});
		else stB[a].insert(b),stB[b].insert(a);
	}
	for(int i=1;i<n;++i){
		if(que.empty())return puts("NO"),0;
		int a=que.front().first,b=que.front().second,A=hd(a),B=hd(b);que.pop();
		if(A==B){--i;continue;}
		if(sz[A]>sz[B])std::swap(A,B),std::swap(a,b);
		fa[A]=B;sz[B]+=sz[A];
		stA[A].erase(b);stB[A].erase(b);
		stA[B].erase(a);stB[B].erase(a);
		for(int j:stA[A]){
			j=hd(j);
			if(j==A||j==B)continue;
			if(stB[B].count(j))que.push({j,B});
			else{
				stA[j].erase(A);stA[j].insert(B);
				stA[B].insert(j);
			}
		}
		stA[A].clear();
		for(int j:stB[A]){
			j=hd(j);
			if(j==A||j==B)continue;
			if(stA[B].count(j))que.push({j,B});
			else{
				stB[j].erase(A);stB[j].insert(B);
				stB[B].insert(j);
			}
		}
		stB[A].clear();
	}
	return puts("YES"),0;
}

```