#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;

const int N = 1e5 + 10;

set<pip> c[N]; int p[N];

set<pii> eG[2], eB;
pii swp(pii x){ if (x.first < x.second) return x; else return pii(x.second, x.first); }

void insG(int G, int u, int v){
	pii e = swp(pii(u, v));

	c[u].insert(pip(G, e));
	c[v].insert(pip(G, e));

	if (eG[1 - G].count(e)) eB.insert(e);
	eG[G].insert(e);
}

void ersG(int G, int u, int v){
	pii e = swp(pii(u, v));

	c[u].erase(pip(G, e));
	c[v].erase(pip(G, e));

	eB.erase(e);
	eG[G].erase(e);
}

int findpar(int u){ return (p[u] == u ? u : p[u] = findpar(p[u])); }

void mrg(int u, int v){
	u = findpar(u), v = findpar(v);
	if (c[v].size() > c[u].size()) swap(u, v);
	p[v] = u;

	while(c[v].size()){
		pip e = *c[v].begin();
		ersG(e.first, e.second.first, e.second.second);
		if (e.second.first == v) e.second.first = u;
		if (e.second.second == v) e.second.second = u;
		insG(e.first, e.second.first, e.second.second);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);

	int n; cin >> n;
	iota(p, p + n, 0);
	for (int k = 0; k < 2; k++)
		for (int i = 0; i < n - 1; i++){
			int u, v; cin >> u >> v; u--; v--;
			insG(k, u, v);
		}

	int cnt = 0;
	while(eB.size()){
		cnt++;
		pii e = *eB.begin(); ersG(0, e.first, e.second); ersG(1, e.first, e.second);
		mrg(e.first, e.second);
	}

	if (cnt == n - 1) cout << "YES\n";
	else cout << "NO\n";
}
### Prompt

Your challenge is to write 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;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;

const int N = 1e5 + 10;

set<pip> c[N]; int p[N];

set<pii> eG[2], eB;
pii swp(pii x){ if (x.first < x.second) return x; else return pii(x.second, x.first); }

void insG(int G, int u, int v){
	pii e = swp(pii(u, v));

	c[u].insert(pip(G, e));
	c[v].insert(pip(G, e));

	if (eG[1 - G].count(e)) eB.insert(e);
	eG[G].insert(e);
}

void ersG(int G, int u, int v){
	pii e = swp(pii(u, v));

	c[u].erase(pip(G, e));
	c[v].erase(pip(G, e));

	eB.erase(e);
	eG[G].erase(e);
}

int findpar(int u){ return (p[u] == u ? u : p[u] = findpar(p[u])); }

void mrg(int u, int v){
	u = findpar(u), v = findpar(v);
	if (c[v].size() > c[u].size()) swap(u, v);
	p[v] = u;

	while(c[v].size()){
		pip e = *c[v].begin();
		ersG(e.first, e.second.first, e.second.second);
		if (e.second.first == v) e.second.first = u;
		if (e.second.second == v) e.second.second = u;
		insG(e.first, e.second.first, e.second.second);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);

	int n; cin >> n;
	iota(p, p + n, 0);
	for (int k = 0; k < 2; k++)
		for (int i = 0; i < n - 1; i++){
			int u, v; cin >> u >> v; u--; v--;
			insG(k, u, v);
		}

	int cnt = 0;
	while(eB.size()){
		cnt++;
		pii e = *eB.begin(); ersG(0, e.first, e.second); ersG(1, e.first, e.second);
		mrg(e.first, e.second);
	}

	if (cnt == n - 1) cout << "YES\n";
	else cout << "NO\n";
}
```