#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second

const int maxn=1e5+10;

int n,f[maxn];
set<int> r[maxn],b[maxn];
queue<pair<int,int> > q;

int find(int x) {return x==f[x]?x:f[x]=find(f[x]);}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	for (i=1;i<=n;i++) f[i]=i;
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		r[u].insert(v);
		r[v].insert(u);
	}
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		b[u].insert(v);
		b[v].insert(u);
		if (r[u].count(v))
			q.push(make_pair(u,v));
	}
	while (!q.empty())
	{
		u=find(q.front().X);
		v=find(q.front().Y);
		q.pop();
		if (u==v) continue;
		if (r[u].size()+b[u].size()<r[v].size()+b[v].size()) swap(u,v);
		set<int>::iterator it;
		for (it=r[v].begin();it!=r[v].end();it++)
		{
			int tmp=find(*it);
			r[u].insert(tmp);
			r[tmp].insert(u);
			if (b[u].count(tmp))
				q.push(make_pair(u,tmp));
		}
		for (it=b[v].begin();it!=b[v].end();it++)
		{
			int tmp=find(*it);
			b[u].insert(tmp);
			b[tmp].insert(u);
			if (r[u].count(tmp))
				q.push(make_pair(u,tmp));
		}
		r[v].clear();
		b[v].clear();
		f[v]=u;
	}
	for (i=2;i<=n;i++)
		if (find(i)!=find(1)) {puts("NO"); return 0;}
	puts("YES");
}

### Prompt

Generate 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>
using namespace std;
#define X first
#define Y second

const int maxn=1e5+10;

int n,f[maxn];
set<int> r[maxn],b[maxn];
queue<pair<int,int> > q;

int find(int x) {return x==f[x]?x:f[x]=find(f[x]);}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	for (i=1;i<=n;i++) f[i]=i;
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		r[u].insert(v);
		r[v].insert(u);
	}
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		b[u].insert(v);
		b[v].insert(u);
		if (r[u].count(v))
			q.push(make_pair(u,v));
	}
	while (!q.empty())
	{
		u=find(q.front().X);
		v=find(q.front().Y);
		q.pop();
		if (u==v) continue;
		if (r[u].size()+b[u].size()<r[v].size()+b[v].size()) swap(u,v);
		set<int>::iterator it;
		for (it=r[v].begin();it!=r[v].end();it++)
		{
			int tmp=find(*it);
			r[u].insert(tmp);
			r[tmp].insert(u);
			if (b[u].count(tmp))
				q.push(make_pair(u,tmp));
		}
		for (it=b[v].begin();it!=b[v].end();it++)
		{
			int tmp=find(*it);
			b[u].insert(tmp);
			b[tmp].insert(u);
			if (r[u].count(tmp))
				q.push(make_pair(u,tmp));
		}
		r[v].clear();
		b[v].clear();
		f[v]=u;
	}
	for (i=2;i<=n;i++)
		if (find(i)!=find(1)) {puts("NO"); return 0;}
	puts("YES");
}

```