#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
using namespace std;
set<int>::iterator it;
set<int>::iterator it2;
set<int>s[100005];
queue<pair<int,int> >q;
map<long long,int>mp;
int f[100005];
int getf(int x){return (f[x]==x)?x:(f[x]=getf(f[x]));}
int n;
int main()
{
	scanf("%d",&n);
	int i;
	for(i=1;i<=n-1;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		s[x].insert(y);
		s[y].insert(x);
	}
	for(i=1;i<=n-1;i++)
    {
    	int x,y;
    	scanf("%d%d",&x,&y);
		if(s[x].find(y)!=s[x].end()) 
		    q.push(make_pair(x,y));
		else
		{
			s[x].insert(y);
		    s[y].insert(x);
		}
	}
	for(i=1;i<=n;i++)
	    f[i]=i;
	for(i=1;i<n;i++)
    {
    	int x,y;
    	if(q.empty())
    	{
    		cout<<"NO";
    	    return 0;
		}
		x=q.front().first;
		y=q.front().second;
		q.pop();
		x=getf(x);
		y=getf(y);
		if(s[x].size()>s[y].size())
		    swap(x,y);
		f[x]=y;
	    s[x].erase(y);
	    s[y].erase(x);
	    for(it=s[x].begin();it!=s[x].end();it++)
	    {
	    	int num=*it;
	    	if(num==x)
			    continue;
	        s[num].erase(x);
	        if(s[y].find(num)!=s[y].end())
		        q.push(make_pair(y,num));
			else
			{
				s[num].insert(y);
			    s[y].insert(num);
			}
		}
		s[x].clear();
	}
	cout<<"YES";
}