#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

vector<pair<int, int> > E[2];
vector<int> G[2][100005];
const long long pr = 100000000000031;

map<pair<int, int>, int> cnt;
set<pair<int, int> > in;

int N;

void add(pair<int, int>& e)
{
	if (e.first > e.second) swap(e.first,e.second);
	int &a = cnt[e];
	if (++a == 2) in.insert(e);
}

void del(pair<int, int>& e)
{
	if (e.first > e.second) swap(e.first,e.second);
	auto I = cnt.find(e);
	I->second--;
	if (I->second == 0) cnt.erase(I);
	else if (I->second == 1) in.erase(e);
}

int main()
{
	scanf ("%d",&N);

	for (int k=0;k<2;k++){
		for (int i=1;i<N;i++){
			int x,y; scanf ("%d %d",&x,&y);
			if (x > y) swap(x,y);
			G[k][x].push_back(E[k].size());
			G[k][y].push_back(E[k].size());
			E[k].push_back({x,y});
			add(E[k].back());
		}
	}

	int d = N-1;
	while (!in.empty()){
		int x = in.begin()->first, y = in.begin()->second;
		if (G[0][x].size() + G[1][x].size() > G[0][y].size() + G[1][y].size()) swap(x,y);
		for (int k=0;k<2;k++){
			vector<pair<int, int> > &e = E[k];
			vector<int> &a = G[k][x];
			vector<int> &b = G[k][y];
			for (auto &i : a){
				if (e[i].first == e[i].second) continue;
				del(e[i]);
				if (e[i].first == x) e[i].first = y;
				if (e[i].second == x) e[i].second = y;
				if (e[i].first == e[i].second) continue;
				b.push_back(i);
				add(e[i]);
			}
			a.clear();
		}
		d--;
	}

	puts(d?"NO":"YES");

	return 0;
}
### Prompt

Please provide a CPP coded solution to the problem described below:

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 <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

vector<pair<int, int> > E[2];
vector<int> G[2][100005];
const long long pr = 100000000000031;

map<pair<int, int>, int> cnt;
set<pair<int, int> > in;

int N;

void add(pair<int, int>& e)
{
	if (e.first > e.second) swap(e.first,e.second);
	int &a = cnt[e];
	if (++a == 2) in.insert(e);
}

void del(pair<int, int>& e)
{
	if (e.first > e.second) swap(e.first,e.second);
	auto I = cnt.find(e);
	I->second--;
	if (I->second == 0) cnt.erase(I);
	else if (I->second == 1) in.erase(e);
}

int main()
{
	scanf ("%d",&N);

	for (int k=0;k<2;k++){
		for (int i=1;i<N;i++){
			int x,y; scanf ("%d %d",&x,&y);
			if (x > y) swap(x,y);
			G[k][x].push_back(E[k].size());
			G[k][y].push_back(E[k].size());
			E[k].push_back({x,y});
			add(E[k].back());
		}
	}

	int d = N-1;
	while (!in.empty()){
		int x = in.begin()->first, y = in.begin()->second;
		if (G[0][x].size() + G[1][x].size() > G[0][y].size() + G[1][y].size()) swap(x,y);
		for (int k=0;k<2;k++){
			vector<pair<int, int> > &e = E[k];
			vector<int> &a = G[k][x];
			vector<int> &b = G[k][y];
			for (auto &i : a){
				if (e[i].first == e[i].second) continue;
				del(e[i]);
				if (e[i].first == x) e[i].first = y;
				if (e[i].second == x) e[i].second = y;
				if (e[i].first == e[i].second) continue;
				b.push_back(i);
				add(e[i]);
			}
			a.clear();
		}
		d--;
	}

	puts(d?"NO":"YES");

	return 0;
}
```