#include <bits/stdc++.h>
#define x first
#define y second
#define N 100050
using namespace std;
typedef pair<int,int> pii;
map<pii,int> mp;
vector<int> e[N];
queue<pii> q;
int fa[N],siz[N],tot,n;

pii MP(int a,int b) {if (a>b) swap(a,b); return make_pair(a,b);}

inline int rd() {int r;scanf("%d",&r);return r;}

void link(int a,int b) {
	e[a].push_back(b);
	e[b].push_back(a);
	mp[MP(a,b)]++;
}

int gf(int u) {return fa[u]==u?u:gf(fa[u]);}

int main() {
	n = rd();
	for (int i=1;i<=n;i++) fa[i] = i;
	for (int i=1;i<=2*n-2;i++) link(rd(), rd());
	
	for (map<pii,int>::iterator it=mp.begin();it!=mp.end();it++)
		if (it->y == 2) q.push(it->x);
		
	while (!q.empty()) {
		pii u = q.front(); q.pop();
		int a = gf(u.x), b = gf(u.y);
		if (a == b) continue;
		++tot;
		if (siz[a] < siz[b]) swap(a, b);
		for (int i=0;i<(int)e[b].size();i++) {
			int t=gf( e[b][i] );
			if (t == a) continue;
			e[a].push_back(t);
			mp[ MP(b, t) ]--;
			mp[ MP(a, t) ]++;
			if (mp[ MP(a, t) ] == 2) q.push( MP(a, t) ); 
		}
		e[b].clear();
		fa[b] = a;
	}
	
	puts(tot==n-1?"YES":"NO");	
	return 0;
}
### Prompt

Create a solution in Cpp for 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>
#define x first
#define y second
#define N 100050
using namespace std;
typedef pair<int,int> pii;
map<pii,int> mp;
vector<int> e[N];
queue<pii> q;
int fa[N],siz[N],tot,n;

pii MP(int a,int b) {if (a>b) swap(a,b); return make_pair(a,b);}

inline int rd() {int r;scanf("%d",&r);return r;}

void link(int a,int b) {
	e[a].push_back(b);
	e[b].push_back(a);
	mp[MP(a,b)]++;
}

int gf(int u) {return fa[u]==u?u:gf(fa[u]);}

int main() {
	n = rd();
	for (int i=1;i<=n;i++) fa[i] = i;
	for (int i=1;i<=2*n-2;i++) link(rd(), rd());
	
	for (map<pii,int>::iterator it=mp.begin();it!=mp.end();it++)
		if (it->y == 2) q.push(it->x);
		
	while (!q.empty()) {
		pii u = q.front(); q.pop();
		int a = gf(u.x), b = gf(u.y);
		if (a == b) continue;
		++tot;
		if (siz[a] < siz[b]) swap(a, b);
		for (int i=0;i<(int)e[b].size();i++) {
			int t=gf( e[b][i] );
			if (t == a) continue;
			e[a].push_back(t);
			mp[ MP(b, t) ]--;
			mp[ MP(a, t) ]++;
			if (mp[ MP(a, t) ] == 2) q.push( MP(a, t) ); 
		}
		e[b].clear();
		fa[b] = a;
	}
	
	puts(tot==n-1?"YES":"NO");	
	return 0;
}
```