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>
using namespace std;
long long n,cnt;
long long fa[100005];
set<long long>a[100005];
struct node
{
	long long x,y;
};
bool operator <(node aa,node bb)
{
	return aa.x==bb.x?aa.y<bb.y:aa.x<bb.x;
}
queue<node>q;
map<node,long long>mp;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return ff*x;
}
void write(long long z)
{
	if(z<0){putchar('-');z=-z;}
	if(z>=10){write(z/10);}
	putchar(z%10+'0');
}
node bh(long long aa,long long bb)
{
	node A;
	A.x=min(aa,bb);
	A.y=max(aa,bb);
	return A;
}
int getfa(int aa)
{
	return fa[aa]==aa?aa:fa[aa]=getfa(fa[aa]);
}
int main()
{
	n=read();
	for(long long i=1;i<=n;++i) fa[i]=i;
	for(long long i=1;i<n*2-1;++i) 
	{
		long long x=read(),y=read();
		a[x].insert(y);
		a[y].insert(x);
		node aa=bh(x,y);
		if(++mp[aa]==2) cnt++,q.push(aa);
	}
	while(!q.empty())
	{
		node kk=q.front();
		q.pop();
		long long X=getfa(kk.x),Y=getfa(kk.y);
		if(X==Y) continue;
		if(a[X].size()<a[Y].size()) swap(X,Y);
		a[X].erase(Y);
		for(set<long long>::iterator it=a[Y].begin();it!=a[Y].end();++it)
		{
			long long tmp=(*it);
			if(tmp==X) continue;
			a[X].insert(tmp);
			a[tmp].erase(Y);
			a[tmp].insert(X);
			if(++mp[bh(X,tmp)]==2) cnt++,q.push(bh(X,tmp));
		}
		fa[Y]=X;
		a[Y].clear();
	}
	if(cnt==n-1) puts("YES");
	else puts("NO");
	return 0;
}