#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
vector<pair<lli,lli>> v;
bool vis[500010];
bool ng;

void func(lli now){
	if(ng)return;
	if(vis[now])return;

	vis[now]=true;

	REP(i,now+1,n){
		if(v[now].second<v[i].first)break;
		if(v[i].second<v[now].second)continue;

		LOG4(v[now].first,v[now].second,v[i].first,v[i].second);
		if(uf.same(now,i)){
			cout<<"NO"<<endl;
			ng=true;
			return;
		}
		uf.unite(i,now);
		func(i);
	}
}

void solve(){

	cin>>n;

	v.resize(n);

	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		v[i]={a,b};
	}
	SORT(v);

	REP(i,0,n){
		func(i);
	}

	if(!ng){
		set<lli> roots;
		REP(i,0,n)roots.insert(uf.root(i));
		if(roots.size()==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return;
}

int main(){

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
lli atob[500010*2];
lli btoa[500010*2];
lli atoin[500010*2];
lli btoin[500010*2];
lli intoa[500010*2];
lli intob[500010*2];

void solve(){

	cin>>n;

	priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> q;

	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		q.push({a,i});
		q.push({b,i});
		atob[a]=b;
		btoa[b]=a;
		atoin[a]=i;
		btoin[b]=i;
		intoa[i]=a;
		intob[i]=b;
	}

	set<lli> s;

	lli cnt = 0;
	REP(i,1,2*n+1){
		LOG2(i,q.size());
		if(cnt>=n){
			cout<<"NO"<<endl;
			return;
		}
		while(q.size() && q.top().first==i){
			pair<lli,lli> top = q.top();
			q.pop();
			LOG2(top.first,top.second);
			if(s.find(intob[top.second])!=s.end()){
				s.erase(intob[top.second]);
				continue;
			}
			lli nowI = top.second;
			for(auto e:s){

				LOG2(top.second,atoin[e]);
				LOG2(intoa[e],intoa[nowI]);
				if(intob[nowI]<e)break;
				uf.unite(nowI,btoin[e]);
				cnt++;
			}
			s.insert(intob[top.second]);
		}
	}

	set<lli> anss;
	REP(i,0,n){
		LOG2(i,uf.root(i));
		anss.insert(uf.root(i));
	}

	if(anss.size()==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
map<lli,lli> atob;
map<lli,lli> btoa;
map<lli,lli> atoin;
map<lli,lli> btoin;
map<lli,lli> intoa;
map<lli,lli> intob;

void solve(){

	cin>>n;

	priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> q;

	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		q.push({a,i});
		q.push({b,i});
		atob[a]=b;
		btoa[b]=a;
		atoin[a]=i;
		btoin[b]=i;
		intoa[i]=a;
		intob[i]=b;
	}

	set<lli> s;

	lli cnt = 0;
	REP(i,1,2*n+1){
		LOG2(i,q.size());
		if(cnt>=n){
			cout<<"NO"<<endl;
			return;
		}
		while(q.size() && q.top().first==i){
			pair<lli,lli> top = q.top();
			q.pop();
			LOG2(top.first,top.second);
			if(s.find(intob[top.second])!=s.end()){
				s.erase(intob[top.second]);
				continue;
			}
			lli nowI = top.second;
			for(auto e:s){

				LOG2(top.second,atoin[e]);
				LOG2(intoa[e],intoa[nowI]);
				if(intob[nowI]<e)break;
				uf.unite(nowI,btoin[e]);
				cnt++;
			}
			s.insert(intob[top.second]);
		}
	}

	set<lli> anss;
	REP(i,0,n){
		LOG2(i,uf.root(i));
		anss.insert(uf.root(i));
	}

	if(anss.size()==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
vector<pair<lli,lli>> v;
bool vis[500010];
bool ng;

void func(lli now){
	if(ng)return;
	if(vis[now])return;

	vis[now]=true;

	REP(i,now+1,n){
		if(v[now].second<v[i].first)break;
		if(v[i].second<v[now].second)continue;

		LOG4(v[now].first,v[now].second,v[i].first,v[i].second);
		if(uf.same(now,i)){
			if(!ng)cout<<"NO"<<endl;
			ng=true;
			return;
		}
		uf.unite(i,now);
		func(i);
		if(ng)break;
	}
}

void solve(){

	cin>>n;

	v.resize(n);

	REP(i,0,n){
		lli a,b;
		//scanf("%d %d",&a,&b);
		cin>>a>>b;
		v[i]={a,b};
	}
	SORT(v);

	REP(i,0,n){
		func(i);
	}

	if(!ng){
		set<lli> roots;
		REP(i,0,n)roots.insert(uf.root(i));
		if(roots.size()==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return;
}

int main(){

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli n;
typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N=5*1e5+10){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

UnionFind uf;
map<lli,lli> atob;
map<lli,lli> btoa;
map<lli,lli> atoin;
map<lli,lli> intoa;
map<lli,lli> intob;

void solve(){

	cin>>n;

	priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> q;

	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		q.push({a,i});
		q.push({b,i});
		atob[a]=b;
		btoa[b]=a;
		atoin[a]=i;
		intoa[i]=a;
		intob[i]=b;
	}

	set<lli> s;

	lli cnt = 0;
	REP(i,1,2*n+1){
		LOG2(i,q.size());
		if(cnt>=n){
			cout<<"NO"<<endl;
			return;
		}
		while(q.size() && q.top().first==i){
			pair<lli,lli> top = q.top();
			q.pop();
			LOG2(top.first,top.second);
			if(s.find(top.second)!=s.end()){
				s.erase(top.second);
				continue;
			}
			lli nowI = top.second;
			for(auto e:s){

				LOG2(top.second,atoin[e]);
				LOG2(intoa[e],intoa[nowI]);
				if(intob[nowI]<intob[e])continue;
				uf.unite(nowI,e);
				cnt++;
			}
			s.insert(top.second);
		}
	}

	set<lli> anss;
	REP(i,0,n){
		LOG2(i,uf.root(i));
		anss.insert(uf.root(i));
	}

	if(anss.size()==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	lli t;
	//cin>>t;
	t=1;
	while(t--)solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], lp, rp, par[MAXN], cmp;
bool mark[MAXN];
set<int> s;

int root(int v) { return (par[v]? par[v] = root(par[v]): v); }
bool mrg(int v, int u) { cmp -= root(v) != root(u); return (root(v) == root(u)? false: par[root(v)] = root(u)); }

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, cmp = n;
	for (int i = 1; i <= n; i++)
		cin >> lp >> rp, l[rp] = lp, r[lp] = rp;
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i))
		while (itr != s.end() && *itr < r[i])
			if (!mrg(l[*itr], i)) puts( "NO"), exit(0);
			else	++itr;
	if (cmp != 1)	puts("NO"), exit(0);
	puts("YES");
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], lp, rp, par[MAXN], cmp;
bool mark[MAXN];
set<int> s;

int root(int v) { return (par[v]? par[v] = root(par[v]): v); }
bool mrg(int v, int u) { cmp -= root(v) != root(u); return (root(v) == root(u)? false: par[root(v)] = root(u)); }
void out(bool ret, string st) {
	if (ret)	cout << st << endl, exit(0);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, cmp = n;
	for (int i = 1; i <= n; i++) {
		cin >> lp >> rp;
		l[rp] = lp, r[lp] = rp;
	}
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i))
		while (itr != s.end() && *itr < r[i]) {
			out(!mrg(l[*itr], i), "NO");
			++itr;
		}
	out(cmp != 1, "NO");
	cout << "YES" << endl;
	return 0;
}


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];
set<int> rn, rs;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mx = max(mx, l);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int i = 1, j = r[1];
	rs.insert(r[1]);
	while (i < j) {
		i++;
		if (!r[i])
			continue;
		while (rn.lower_bound(i) != rn.end() && *rn.lower_bound(i) < r[i])
			rs.insert(*rn.lower_bound(i)), rn.erase(rn.lower_bound(i));
		bool flag = false;
		if (r[i] < j) {
			auto itr = rs.lower_bound(i);
			if (itr != rs.end() && *itr > r[i])
				rn.insert(r[i]);
			else
				rs.insert(r[i]);
		}
		else
			rs.insert(r[i]), j = r[i];
	}
	if (i != 2 * n || rn.size())
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], mn = MAXN, mx, m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mn = min(l, mn);
		mx = max(l, mx);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int rp = r[mn];
	while (rp < mx && mn + 1 < rp) {
		mn++;
		rp = max(rp, r[mn]);
	}
	if (rp < mx)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, m;

int r[MAXN], l[MAXN], cnt;
bool mark[MAXN];
vector<int> adj[MAXN];
set<int> s;

void dfs(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i])
			dfs(i);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int tmp;
		cin >> tmp;
		cin >> r[tmp];
		l[r[tmp]] = tmp;
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		if (!s.size()) {
			s.insert(r[i]);
			continue;
		}
		auto itr = s.lower_bound(i);
		while (itr != s.end() && *itr < r[i]) {
			adj[l[*itr]].pb(i);
			adj[i].pb(l[*itr]);
			m++;
			if (m > n - 1) {
				return cout << "NO" << endl, 0;
			}
			++itr;
		}
		s.insert(r[i]);
	}
	for (int i = 1; i <= 2 * n; i++)
		if (r[i] && !mark[i])
			++cnt, dfs(i);
	if (cnt == 1 && m == n - 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];
vector<int> rs;
set<int> rn;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mx = max(mx, l);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int i = 1, j = r[1];
	rs.pb(r[1]);
	while (i < j) {
		i++;
		if (!r[i])
			continue;
		while (rn.lower_bound(i) != rn.end() && *rn.lower_bound(i) < r[i])
			rn.erase(rn.lower_bound(i));
		bool flag = false;
		if (r[i] < j) {
			auto itr = lower_bound(rs.begin(), rs.end(), i);
			if (*itr > r[i])
				rn.insert(r[i]);
		}
		else
			rs.pb(r[i]), j = r[i];
	}
	if (i != 2 * n || rn.size())
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], cnt;
bool mark[MAXN];
vector<int> adj[MAXN];
set<int> s;

void dfs(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i])
			dfs(i);
}

void out(bool ret, string s) {
	if (ret)	cout << s << endl, exit(0);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int tmp;
		cin >> tmp;
		cin >> r[tmp];
		l[r[tmp]] = tmp;
	}
	for (int i = 1; i <= 2 * n; i++) {
		auto itr = s.lower_bound(i);
		while (itr != s.end() && *itr < r[i]) {
			adj[l[*itr]].pb(i), adj[i].pb(l[*itr]);
			m++, itr++;
			out(m > n - 1, "NO");
		}
		s.insert(r[i]);
	}
	for (int i = 1; i <= 2 * n; i++)
		if (r[i] && !mark[i])
			++cnt, dfs(i);
	out((cnt == 1 && m == n - 1), "YES");
	cout << "NO" << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], lp, rp, par[MAXN], cmp;
bool mark[MAXN];
set<int> s;

int root(int v) { return (par[v]? par[v] = root(par[v]): v); }
bool mrg(int v, int u) { return (root(v) == root(u)? false: par[root(v)] = root(u)); }

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, cmp = n;
	for (int i = 1; i <= n; i++)
		cin >> lp >> rp, l[rp] = lp, r[lp] = rp;
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i))
		while (itr != s.end() && *itr < r[i])
			if (!mrg(l[*itr], i)) puts( "NO"), exit(0);
			else	++itr, cmp--;
	if (cmp != 1)	puts("NO"), exit(0);
	puts("YES");
	return 0;
}


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 2 * 100 * 1000 + 17;

int n, seg[MAXN << 2], mn = MAXN, mx, m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mn = min(l, mn);
		mx = max(l, mx);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int rp = r[mn];
	while (rp < mx && mn + 1 < rp) {
		mn++;
		rp = max(rp, r[mn]);
	}
	if (rp < mx)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


#include <bits/stdc++.h>
using namespace std;

int n, m, r[1000017], l[1000017], lp, rp, par[1000017], cmp;
set<int> s;

int root(int v) { return (par[v]? par[v] = root(par[v]): v); }
bool mrg(int v, int u) { return (root(v) == root(u)? false: par[root(v)] = root(u)); }

int main() {
	cin >> n, cmp = n;
	for (int i = 1; i <= n; i++)	cin >> lp >> rp, l[rp] = lp, r[lp] = rp;
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i)) while (itr != s.end() && *itr < r[i])
		if (!mrg(l[*itr], i)) puts( "NO"), exit(0);
		else	++itr, cmp--;
	if (cmp != 1)	puts("NO"), exit(0);
	puts("YES");
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], lp, rp;
bool mark[MAXN];
vector<int> adj[MAXN];
set<int> s;

void dfs(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i])
			dfs(i);
}

void out(bool ret, string s) {
	if (ret)	cout << s << endl, exit(0);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> lp >> rp;
		l[rp] = lp, r[lp] = rp;
	}
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; itr = s.lower_bound(i), s.insert(r[i]), i++)
		while (itr != s.end() && *itr < r[i]) {
			adj[l[*itr]].pb(i), adj[i].pb(l[*itr]);
			m++, itr++;
			out(m > n - 1, "NO");
		}
	dfs(1);
	for (int i = 1; i <= 2 * n; i++)
		out((r[i] && !mark[i]) || (m != n - 1), "NO");
	cout << "YES" << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], lp, rp, par[MAXN], cmp;
bool mark[MAXN];
set<int> s;

int root(int v) { return (par[v]? par[v] = root(par[v]): v); }
void mrg(int v, int u) { cmp -= (root(v) != root(u)), par[root(v)] = root(u); }

void out(bool ret, string s) {
	if (ret)	cout << s << endl, exit(0);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, cmp = n;
	for (int i = 1; i <= n; i++) {
		cin >> lp >> rp;
		l[rp] = lp, r[lp] = rp;
	}
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i))
		while (itr != s.end() && *itr < r[i]) {
			mrg(l[*itr], i);
			m++, itr++;
			out(m > n - 1, "NO");
		}
	out((m != n - 1) || (cmp != 1), "NO");
	cout << "YES" << endl;
	return 0;
}


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];
vector<int> rs;
deque<int> rn;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mx = max(mx, l);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int i = 1, j = r[1];
	rs.pb(r[1]);
	while (i < j) {
		i++;
		if (!r[i])
			continue;
		while (rn.size() && rn.front() < r[i])
			rn.pop_front();
		bool flag = false;
		if (r[i] < j) {
			auto itr = lower_bound(rs.begin(), rs.end(), i);
			if (*itr > r[i])
				rn.pb(r[i]);
		}
		else
			rs.pb(r[i]), j = r[i];
	}
	if (i != 2 * n || rn.size())
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int MAXN =  1000 * 1000 + 17;

int n, m, r[MAXN], l[MAXN], lp, rp;
bool mark[MAXN];
vector<int> adj[MAXN];
set<int> s;

void dfs(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i])
			dfs(i);
}

void out(bool ret, string s) {
	if (ret)	cout << s << endl, exit(0);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> lp >> rp;
		l[rp] = lp, r[lp] = rp;
	}
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i))
		while (itr != s.end() && *itr < r[i]) {
			adj[l[*itr]].pb(i), adj[i].pb(l[*itr]);
			m++, itr++;
			out(m > n - 1, "NO");
		}
	dfs(1);
	for (int i = 1; i <= 2 * n; i++)
		out((r[i] && !mark[i]) || (m != n - 1), "NO");
	cout << "YES" << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n, m, r[1000017], l[1000017], lp, rp, par[1000017], cmp;
set<int> s;

int root(int v) { return (par[v]? par[v] = root(par[v]): v); }
bool mrg(int v, int u) { return (root(v) == root(u)? false: par[root(v)] = root(u)); }

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n, cmp = n;
	for (int i = 1; i <= n; i++)
		cin >> lp >> rp, l[rp] = lp, r[lp] = rp;
	auto itr = s.end();
	for (int i = 1; i <= 2 * n; s.insert(r[i]), i++, itr = s.lower_bound(i))
		while (itr != s.end() && *itr < r[i])
			if (!mrg(l[*itr], i)) puts( "NO"), exit(0);
			else	++itr, cmp--;
	if (cmp != 1)	puts("NO"), exit(0);
	puts("YES");
	return 0;
}


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN], l[MAXN], cnt;
bool mark[MAXN];
vector<int> adj[MAXN];
set<int> s;

void dfs(int v) {
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i])
			dfs(i);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int tmp;
		cin >> tmp;
		cin >> r[tmp];
		l[r[tmp]] = tmp;
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		if (!s.size()) {
			s.insert(r[i]);
			continue;
		}
		auto itr = s.lower_bound(i);
		while (itr != s.end() && *itr < r[i]) {
			adj[l[*itr]].pb(i);
			adj[i].pb(l[*itr]);
			++itr;
		}
		s.insert(r[i]);
	}
	for (int i = 1; i <= 2 * n; i++)
		if (r[i] && !mark[i])
			++cnt, dfs(i);
	if (cnt == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];
set<int> rn, rs;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mx = max(mx, l);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int i = 1, j = r[1];
	rs.insert(r[1]);
	while (i < j) {
		i++;
		if (!r[i])
			continue;
		if (r[i] < j) {
			auto itr = rs.lower_bound(i);
			if (itr != rs.end() && *itr < r[i])
				rn.insert(r[i]);
			else
				rs.insert(r[i]);
		}
		else
			rs.insert(r[i]), j = r[i];
		while (rn.lower_bound(i) != rn.end() && *rn.lower_bound(i) < r[i])
			rs.insert(*rn.lower_bound(i)), rn.erase(rn.lower_bound(i));
		bool flag = false;

	//	cerr << i << ' ' << j << ' ' << r[i] << ' ' << rs.size() << ' ' << rn.size() << endl;
	}
	if (i != 2 * n || rn.size())
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


//IOI 2021
//this will accept, By the order of the peaky fucking blinders
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN =  1000 * 1000 + 17;

int n, seg[MAXN << 2], mn = MAXN, mx, m;

void add(int pos, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (pos < l || r <= pos)
		return;
	if (l + 1 == r) {
		seg[v]++;
		return;
	}
	add(pos, v << 1, l, l + r >> 1);
	add(pos, v << 1 | 1, l + r >> 1, r);
	seg[v] = seg[v << 1] + seg[v << 1 | 1];
}

int get(int lp, int rp, int v = 1, int l = 1, int r = 2 * n + 1) {
	if (rp <= l || r <= lp)
		return 0;
	if (lp <= l && r <= rp)
		return seg[v];
	return get(lp, rp, v << 1, l, l + r >> 1) +
		get(lp, rp, v << 1 | 1, l + r >> 1, r);
}

int r[MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int l;
		cin >> l;
		cin >> r[l];
		mn = min(l, mn);
		mx = max(l, mx);
	}
	for (int i = 1; i <= 2 * n; i++) {
		if (!r[i])
			continue;
		m += get(i, r[i]);
		add(r[i]);
	}
	if (m != n - 1)
		return cout << "NO" << endl, 0;
	int rp = r[mn];
	while (rp < mx && mn < rp) {
		mn++;
		rp = max(rp, r[mn]);
	}
	if (rp < mx)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

/*
   Don't stare at laptop more than 20 minutes, read problem again :))))
   if you got a formula check it again
   check where you have to output 0 :D
   check if your Solution need long long
   check if you need to use modulo
   you can submit now
*/


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

bool cnt = true;
vector<pi> v;
vector<int> u[N];
bool vis[N];
void dfs(int i,int p) {
    if (!cnt || vis[i]) {
        cnt = false;
        return;
    }
    vis[i] = true;
    for (auto it:u[i]) {
        if (it!=p) {
            dfs(it, i);
        }
    }
}
bool isect (pi& a, pi& b) {
    return (a.second > b.first && a.second < b.second);
}
multiset<pi> temp;
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    sort(all(v));
    int edges = 0;
    REP(i,0,n-1) {
        while (!temp.empty() && (*(temp.begin())).first < v[i].first) {
            temp.erase(temp.begin());
        }
        auto it = temp.begin();
        while (it != temp.end()) {
            if ((*it).first > v[i].second) {
                break;
            }
            if (edges>=n) {
                break;
            }
            edges++;
            u[i].pb((*it).second);
            u[(*it).second].pb(i);
            it++;
        }
        temp.insert({v[i].second, i});
    }
    if (edges != (n-1)) {
        cout<<"NO";
        return;
    }
    dfs(0,0);
    if (cnt==n) {
        cout<<"YES";
    }
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

int cnt = 0;
bool cycle = false;
vector<pi> v;
vector<int> u[N];
bool vis[N];
void dfs(int i,int p) {
    if (!cycle || vis[i]) {
        cycle = false;
        return;
    }
    vis[i] = true;
    cnt++;
    for (auto it:u[i]) {
        if (it!=p) {
            dfs(it, i);
        }
    }
}
bool isect (pi& a, pi& b) {
    return (a.second > b.first && a.second < b.second);
}
multiset<pi> temp;
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    sort(all(v));
    int edges = 0;
    REP(i,0,n-1) {
        while (!temp.empty() && (*(temp.begin())).first < v[i].first) {
            temp.erase(temp.begin());
        }
        auto it = temp.begin();
        while (it != temp.end()) {
            if ((*it).first > v[i].second) {
                break;
            }
            if (edges>=n) {
                break;
            }
            edges++;
            u[i].pb((*it).second);
            u[(*it).second].pb(i);
            it++;
        }
        temp.insert({v[i].second, i});
    }
    if (edges != (n-1)) {
        cout<<"NO";
        return;
    }
    dfs(0,0);
    if (cnt==n) {
        cout<<"YES";
    }
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

int cnt = 0;
bool cycle = false;
vector<pi> v;
vector<int> u[N];
bool vis[N];
void dfs(int i,int p) {
    if (cycle || vis[i]) {
        cycle = true;
        return;
    }
    vis[i] = true;
    cnt++;
    for (auto it:u[i]) {
        if (it!=p) {
            dfs(it, i);
        }
    }
}
bool isect (pi& a, pi& b) {
    return (a.second > b.first && a.second < b.second);
}
multiset<pi> temp;
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    sort(all(v));
    int edges = 0;
    REP(i,0,n-1) {
        while (!temp.empty() && (*(temp.begin())).first < v[i].first) {
            temp.erase(temp.begin());
        }
        auto it = temp.begin();
        while (it != temp.end()) {
            if ((*it).first > v[i].second) {
                break;
            }
            if (edges>=n) {
                break;
            }
            edges++;
            u[i].pb((*it).second);
            u[(*it).second].pb(i);
            it++;
        }
        temp.insert({v[i].second, i});
    }
    if (edges != (n-1)) {
        cout<<"NO";
        return;
    }
    dfs(0,0);
    if (cnt==n) {
        cout<<"YES";
    }
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

bool cnt = true;
vector<pi> v;
vector<int> u[N];
bool vis[N];
void dfs(int i,int p) {
    if (!cnt || vis[i]) {
        cnt = false;
        return;
    }
    vis[i] = true;
    for (auto it:u[i]) {
        if (it!=p) {
            dfs(it, i);
        }
    }
}
bool isect (pi& a, pi& b) {
    return (a.second > b.first && a.second < b.second);
}
multiset<pi> temp;
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    sort(all(v));
    int edges = 0;
    REP(i,0,n-1) {
        while (!temp.empty() && (*(temp.begin())).first < v[i].first) {
            temp.erase(temp.begin());
        }
        auto it = temp.begin();
        while (it != temp.end()) {
            if ((*it).first > v[i].second) {
                break;
            }
            if (edges>=n) {
                break;
            }
            edges++;
            u[i].pb((*it).second);
            u[(*it).second].pb(i);
            it++;
        }
        temp.insert({v[i].second, i});
    }
    if (edges != (n-1)) {
        cout<<"NO";
        return;
    }
    dfs(0,0);
    if (cnt) {
        cout<<"YES";
    }
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

vector<pi> v;
int deg[N], sum[N<<1];
void update(int i) {
    sum[i] = 1;
    for (i>>=1;i>0;i>>=1) {
        sum[i] = sum[i<<1] + sum[i<<1|1];
    }
}
int sumrange(int l, int r) {
    int ret = 0;
    for (;l<r;l>>=1,r>>=1) {
        if (l&1) ret += sum[l++];
        if (r&1) ret += sum[--r];
    }
    return ret;
}
bool comp(const pi& a, const pi& b) {
    return (a.second > b.second);
}
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    n<<=1;
    sort(all(v));
    for (auto it:v) {
        update(it.second + n-1);
        deg[it.second] += sumrange(it.first + n-1, it.second + n-1);
    }
    mms(sum, 0);
    sort(all(v),comp);
    for (auto it:v) {
        update(it.first + n-1);
        deg[it.second] += sumrange(it.first + n, it.second + n-1);
    }
    bool tree = true;
    int sum = 0;
    for (auto it:v) {
        sum += deg[it.second];
        if (deg[it.second]==0) {
            tree = false;
            break;
        }
    }
    if (!tree || sum&1 || (sum/2)!=(n/2-1)) {
        tree = false;
    }
    if (tree) cout<<"YES";
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

int cnt = 0;
vector<pi> v;
vector<int> u[N];
void dfs(int i, int p) {
    cnt++;
    for (auto it:u[i]) {
        if (it!=p) {
            dfs(it,i);
        }
    }
}
bool isect (pi& a, pi& b) {
    return (a.second > b.first && a.second < b.second);
}
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    sort(all(v));
    int edges = 0;
    REP(i,0,n-1) {
        REP(j,i+1,n-1) {
            if (edges>=n) break;
            else if (isect(v[i], v[j])) {
                edges++;
                u[i].pb(j);
                u[j].pb(i);
            }
        }
    }
    if (edges != (n-1)) {
        cout<<"NO";
        return;
    }
    dfs(0,0);
    if (cnt==n) {
        cout<<"YES";
    }
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e6+5;
const int Q = 301;

int cnt = 0;
vector<pi> v;
vector<int> u[N];
void dfs(int i, int p) {
    cnt++;
    for (auto it:u[i]) {
        if (it!=p) {
            dfs(it,i);
        }
    }
}
bool isect (pi& a, pi& b) {
    return (a.second > b.first && a.second < b.second);
}
multiset<pi> temp;
void solve() {
    int n, x, y;
    cin>>n;
    REP(i,1,n) {
        cin>>x>>y;
        v.pb({x,y});
    }
    if (n==1) {
        cout<<"YES";
        return;
    }
    sort(all(v));
    int edges = 0;
    REP(i,0,n-1) {

        while (!temp.empty() && (*(temp.begin())).first < v[i].first) {
            temp.erase(temp.begin());
        }
        auto it = temp.begin();
        while (it != temp.end()) {
            if ((*it).first > v[i].second) {
                break;
            }
            if (edges>=n) {
                break;
            }
            edges++;
            u[i].pb((*it).second);
            u[(*it).second].pb(i);
            it++;
        }
        temp.insert({v[i].second, i});
    }
    if (edges != (n-1)) {
        cout<<"NO";
        return;
    }
    dfs(0,0);
    if (cnt==n) {
        cout<<"YES";
    }
    else cout<<"NO";
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}
	if(n==1){
	    cout<<"YES\n";
	    return 0;
	}
	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	ll m=3*n;
	unordered_map<ll,ll> next;
	repi(i,2*n,-1){
	    next[i]=m;
	    if(v[i].size()!=0){
	        m=i;
	    }
	}

	rep(i,0,v2.size()){
	    for(j=next[v2[i].F-1];j<v2[i].S;j=next[j]){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}
	ll e=0;

	rep(i,0,v2.size()){
	    rep(j,v2[i].F,v2[i].S){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}
	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	ll m=3*n;
	unordered_map<ll,ll> next;
	repi(i,2*n,-1){
	    next[i]=m;
	    if(v[i].size()!=0){
	        m=i;
	    }
	}

	rep(i,0,v2.size()){
	    for(j=v2[i].F;j<v2[i].S;j=next[j]){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}
	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	ll m=3*n;
	unordered_map<ll,ll> next;
	repi(i,2*n,-1){
	    next[i]=m;
	    if(v[i].size()!=0){
	        m=i;
	    }
	}

	rep(i,0,v2.size()){
	    for(j=next[v2[i].F-1];j<v2[i].S;j=next[j]){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[2*n+1];
	ll l,r;
	map<ll,ll> map1;
	ll k=1;
	rep(i,0,n){
	    cin>>l>>r;
	    a[r]=l;
	    a[l]=r;
	    map1[l]=k;
	    k++;
	}set<pll> set1;
	pll z;
	ll e=0;
	vll adj[n+1];
	set<pll> :: iterator it;
	rep(i,1,2*n+1){
	    //cout<<i<<endl;
	    if(a[i]<i){
	        it=set1.find(mp(a[i],map1[a[i]]));
	        set1.erase(it);
	    }else{
	        for(it=set1.begin();it!=set1.end();++it){

	            z=*it;
	            if(a[z.F]<a[i]){
	                adj[z.S].pb(map1[i]);;
	                adj[map1[i]].pb(z.S);
	                e++;
	                //cout<<z.F<<" "<<i<<endl;
	                if(e>n-1){
	                    cout<<"NO\n";
	                    return 0;
	                }
	            }

	        }
	        set1.insert(mp(i,map1[i]));
	    }
	}
	//cout<<e<<endl;
	if(e!=n-1){

	    cout<<"NO\n";
	    return 0;
	}

	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(1);
	vis[1]=1;
	ll z1;
	while(!queue.empty()){
	    z1=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z1].size()){
	        if(!vis[adj[z1][i]]){
	            vis[adj[z1][i]]=1;
	            queue.pb(adj[z1][i]);
	        }
	    }
	}
	rep(i,1,n+1){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	//	cout<<n<<endl;
	if(n==1){
	    cin>>i>>j;
	    cout<<"YES\n";
	    return 0;
	}
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}

	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	ll m=3*n;
	unordered_map<ll,ll> next;
	repi(i,2*n,-1){
	    next[i]=m;
	    if(v[i].size()!=0){
	        m=i;
	    }
	}

	rep(i,0,v2.size()){
	    for(j=next[v2[i].F-1];j<v2[i].S;j=next[j]){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[2*n+1];
	ll l,r;
	map<ll,ll> map1;
	ll k=1;
	rep(i,0,n){
	    cin>>l>>r;
	    a[r]=l;
	    a[l]=r;
	    map1[l]=k;
	    k++;
	}set<pll> set1;
	pll z;
	ll e=0;
	vll adj[n+1];
	set<pll> :: iterator it;
	rep(i,1,2*n+1){
	    //cout<<i<<endl;
	    if(a[i]<i){
	        it=set1.find(mp(i,map1[a[i]]));
	        set1.erase(it);
	    }else{
	        for(it=set1.begin();it!=set1.end();++it){

	            z=*it;
	            if(z.F<a[i]){
	                adj[z.S].pb(map1[i]);;
	                adj[map1[i]].pb(z.S);
	                e++;
	                //cout<<z.F<<" "<<i<<endl;
	                if(e>n-1){
	                    cout<<"NO\n";
	                    return 0;
	                }
	            }else
	                break;

	        }
	        set1.insert(mp(a[i],map1[i]));
	    }
	}
	//cout<<e<<endl;
	if(e!=n-1){

	    cout<<"NO\n";
	    return 0;
	}

	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(1);
	vis[1]=1;
	ll z1;
	while(!queue.empty()){
	    z1=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z1].size()){
	        if(!vis[adj[z1][i]]){
	            vis[adj[z1][i]]=1;
	            queue.pb(adj[z1][i]);
	        }
	    }
	}
	rep(i,1,n+1){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}
	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	ll m=3*n;
	map<ll,ll> next;
	repi(i,2*n,-1){
	    next[i]=m;
	    if(v[i].size()!=0){
	        m=i;
	    }
	}
	rep(i,0,v2.size()){
	    for(j=v2[i].F;j<v2[i].S;j=next[j]){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n+1];
	init(a,n+1,0);
	ll l,r;
	map<ll,ll> map1;
	ll k=1;
	rep(i,0,n){
	    cin>>l>>r;
	    a[r]=l;
	    a[l]=r;
	    map1[l]=k;
	    k++;
	}set<pll> set1;
	pll z;
	ll e=0;
	vll adj[n+1];
	set<pll> :: iterator it;
	rep(i,1,2*n+1){
	    //cout<<i<<endl;
	    if(a[i]<i){
	        it=set1.find(mp(a[i],map1[a[i]]));
	        set1.erase(it);
	    }else{
	        for(it=set1.begin();it!=set1.end();++it){

	            z=*it;
	            if(a[z.F]<a[i]){
	                adj[z.S].pb(map1[i]);;
	                adj[map1[i]].pb(z.S);
	                e++;
	                //cout<<z.F<<" "<<i<<endl;
	                if(e>n-1){
	                    cout<<"NO\n";
	                    return 0;
	                }
	            }

	        }
	        set1.insert(mp(i,map1[i]));
	    }
	}
	//cout<<e<<endl;
	if(e!=n-1){

	    cout<<"NO\n";
	    return 0;
	}

	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(1);
	vis[1]=1;
	ll z1;
	while(!queue.empty()){
	    z1=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z1].size()){
	        if(!vis[adj[z1][i]]){
	            vis[adj[z1][i]]=1;
	            queue.pb(adj[z1][i]);
	        }
	    }
	}
	rep(i,1,n+1){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}
	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	rep(i,0,v2.size()){
	    rep(j,v2[i].F,v2[i].S){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j,k;
	ll n;
	cin>>n;
	//	cout<<n<<endl;
	if(n==1){
	    cout<<"YES\n";
	    return 0;
	}
	ll x,y,z;
	vpll v[2*n+1];
	vpll v2;
	vll adj[n+1];
	rep(i,0,n){
	    cin>>x>>y;
	    v2.pb(mp(x,y));
	    v[y].pb(mp(x,i));
	}

	ll e=0;
	rep(i,0,2*n+1){
	    sort(v[i].begin(),v[i].end());
	}
	ll m=3*n;
	unordered_map<ll,ll> next;
	repi(i,2*n,-1){
	    next[i]=m;
	    if(v[i].size()!=0){
	        m=i;
	    }
	}

	rep(i,0,v2.size()){
	    for(j=next[v2[i].F-1];j<v2[i].S;j=next[j]){
	        rep(k,0,v[j].size()){
	            if(v[j][k].F<v2[i].F){
	                adj[i].pb(v[j][k].S);
	                adj[v[j][k].S].pb(i);
	                e++;
	            }
	            else
	            break;
	            if(e>n-1){
	                cout<<"NO\n";
	                return 0;
	            }
	        }
	    }

	}
	//cout<<e<<endl;
	if(e!=n-1){
	    cout<<"NO\n";
	    return 0;
	}
	ll vis[n+1];
	init(vis,n+1,0);
	list<ll> queue;
	queue.pb(0);
	vis[0]=1;
	//ll z;
	while(!queue.empty()){
	    z=queue.front();
	    queue.pop_front();
	    rep(i,0,adj[z].size()){
	        if(!vis[adj[z][i]]){
	            vis[adj[z][i]]=1;
	            queue.pb(adj[z][i]);
	        }
	    }
	}
	rep(i,0,n){
	    if(!vis[i]){
	        cout<<"NO\n";
	        return 0;
	    }
	}cout<<"YES\n";
	return 0;

}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

const int N = 1e6 + 5;
int p[N], rnk[N], n, st[N], en[N], s[N], rm[N];
set<int> cur;
vector<int> v;

void init() {
    iota(p, p + N, 0);
}

int fp(int x) {
    return x == p[x] ? x : fp(p[x]);
}

bool con(int x, int y) {
    x = fp(x), y = fp(y);
    if (x == y) return 0;
    if (rnk[x] < rnk[y]) swap(x, y);
    p[y] = x;
    rnk[x]++;
    return 1;
}

bool ch() {
    for (int i = 2; i <= n; i++)
        if (fp(i) != fp(1))
            return 0;
    return 1;
}

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

    cin >> n;
    init();
    for (int i = 1; i <= n; i++) {
        cin >> st[i] >> en[i];
        s[st[i]] = i;
        rm[en[i]] = i;
        v.push_back(st[i]);
        v.push_back(en[i]);
    }

    sort(v.begin(), v.end());

    for (auto i : v) {
        if (rm[i]) cur.erase(en[rm[i]]);
        if (s[i]) {
            for (auto j : cur) {
                if (j > en[s[i]]) break;

                if (!con(s[i], rm[j])) {
                    return cout << "NO", 0;
                }
            }
            cur.insert(en[s[i]]);
        }
    }

    (ch()) ? cout << "YES" : cout << "NO";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

const int N = 1e6 + 5;
int p[N], rnk[N], n, st[N], en[N], s[N], rm[N], cnt;
set<pair<int, int>> cur;

void init() {
    iota(p, p + N, 0);
}

int fp(int x) {
    return x == p[x] ? x : fp(p[x]);
}

bool con(int x, int y) {
    x = fp(x), y = fp(y);
    if (x == y) return 0;
    if (rnk[x] < rnk[y]) swap(x, y);
    p[y] = x;
    rnk[x] += rnk[y];
    return 1;
}

bool ch() {
    for (int i = 2; i <= n; i++)
        if (fp(i) != fp(1))
            return 0;
    return 1;
}

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

    cin >> n;
    init();
    for (int i = 1; i <= n; i++) {
        cin >> st[i] >> en[i];
        s[st[i]] = i;
        rm[en[i]] = i;
    }

    for (int i = 1; i < N; i++) {
        if (rm[i]) cur.erase({en[rm[i]], rm[i]});
        if (s[i]) {
            for (auto j : cur) {
                if (j.first > en[s[i]]) break;

                if (!con(s[i], j.second)) {
                    return cout << "NO", 0;
                }
            }
            cur.insert({en[s[i]], s[i]});
        }
    }

    (ch()) ? cout << "YES" : cout << "NO";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

const int N = 1e6 + 5;
int p[N], rnk[N], n, st[N], en[N], s[N], rm[N];
set<int> cur;
vector<int> v;

void init() {
    iota(p, p + N, 0);
}

int fp(int x) {
    return x == p[x] ? x : fp(p[x]);
}

bool con(int x, int y) {
    x = fp(x), y = fp(y);
    if (x == y) return 0;
    if (rnk[x] > rnk[y]) p[y] = x;
    else if (rnk[y] > rnk[x]) p[x] = y;
    else {
        p[y] = x;
        rnk[x]++;
    }
    return 1;
}

bool ch() {
    for (int i = 2; i <= n; i++)
        if (fp(i) != fp(1))
            return 0;
    return 1;
}

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

    cin >> n;
    init();
    for (int i = 1; i <= n; i++) {
        cin >> st[i] >> en[i];
        s[st[i]] = i;
        rm[en[i]] = i;
        v.push_back(st[i]);
        v.push_back(en[i]);
    }

    sort(v.begin(), v.end());

    for (auto i : v) {
        if (rm[i]) cur.erase(en[rm[i]]);
        if (s[i]) {
            for (auto j : cur) {
                if (j > en[s[i]]) break;

                if (!con(s[i], rm[j])) {
                    return cout << "NO", 0;
                }
            }
            cur.insert(en[s[i]]);
        }
    }

    (ch()) ? cout << "YES" : cout << "NO";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

const int N = 1e6 + 5;
int p[N], rnk[N], n, st[N], en[N], s[N], rm[N];
set<int> cur;
vector<int> v;

void init() {
    iota(p, p + N, 0);
}

int fp(int x) {
    return x == p[x] ? x : fp(p[x]);
}

bool con(int x, int y) {
    x = fp(x), y = fp(y);
    if (x == y) return 0;
    if (rnk[x] <= rnk[y]) swap(x, y);
    p[y] = x;
    rnk[x] += rnk[x] == rnk[y];
    return 1;
}

bool ch() {
    for (int i = 2; i <= n; i++)
        if (fp(i) != fp(1))
            return 0;
    return 1;
}

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

    cin >> n;
    init();
    for (int i = 1; i <= n; i++) {
        cin >> st[i] >> en[i];
        s[st[i]] = i;
        rm[en[i]] = i;
        v.push_back(st[i]);
        v.push_back(en[i]);
    }

    sort(v.begin(), v.end());

    for (auto i : v) {
        if (rm[i]) cur.erase(en[rm[i]]);
        if (s[i]) {
            for (auto j : cur) {
                if (j > en[s[i]]) break;

                if (!con(s[i], rm[j])) {
                    return cout << "NO", 0;
                }
            }
            cur.insert(en[s[i]]);
        }
    }

    (ch()) ? cout << "YES" : cout << "NO";

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

const int N = 1e6 + 5;
int p[N], rnk[N], n, st[N], en[N], s[N], rm[N];
set<int> cur;
vector<int> v;

void init() {
    iota(p, p + N, 0);
}

int fp(int x) {
    return x == p[x] ? x : fp(p[x]);
}

bool con(int x, int y) {
    x = fp(x), y = fp(y);
    if (x == y) return 0;
    if (rnk[x] < rnk[y]) swap(x, y);
    p[y] = x;
    rnk[x] += rnk[y];
    return 1;
}

bool ch() {
    for (int i = 2; i <= n; i++)
        if (fp(i) != fp(1))
            return 0;
    return 1;
}

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

    cin >> n;
    init();
    for (int i = 1; i <= n; i++) {
        cin >> st[i] >> en[i];
        s[st[i]] = i;
        rm[en[i]] = i;
        v.push_back(st[i]);
        v.push_back(en[i]);
    }

    sort(v.begin(), v.end());

    for (auto i : v) {
        if (rm[i]) cur.erase(en[rm[i]]);
        if (s[i]) {
            for (auto j : cur) {
                if (j > en[s[i]]) break;

                if (!con(s[i], rm[j])) {
                    return cout << "NO", 0;
                }
            }
            cur.insert(en[s[i]]);
        }
    }

    (ch()) ? cout << "YES" : cout << "NO";

    return 0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define dd c=getchar()
int read() {int s=0;char c;while (dd,c>'9' || c<'0');while (c>='0' && c<='9') s=s*10+c-'0',dd;return s;}
#undef dd
const int N=2e5+7;
struct edge {
	int t,next;
}e[N<<1];
int n,m,q,cnt,num;
int head[N],u[N],v[N];
void add(int u,int t) {
	e[cnt].t=t;
	e[cnt].next=head[u];
	head[u]=cnt++;
	e[cnt].t=u;
	e[cnt].next=head[t];
	head[t]=cnt++;
}
int tp,t,now;
int low[N],dfn[N],st[N],ins[N],vis[N],bl[N],kin[N];
void Tarjan(int u,int fa) {
	low[u]=dfn[u]=++t;st[++tp]=u;kin[u]=num;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if ((i^1)==fa) continue;
		if (!dfn[v]) {
			Tarjan(v,i);
			low[u]=min(low[u],low[v]);
		}
		else if(!bl[v]) low[u]=min(low[u],dfn[v]);
	}
	if (low[u]==dfn[u]) {
		now++;
		while (tp) {
			int v=st[tp--];
			bl[v]=now;
			if (v==u) break;
		}
	}
}
queue<int> Q;
int dee[N],fa[N][20],up[N],down[N],aup[N],ado[N];
void dfs(int u,int f) {
	int p=0;
	ins[u]=1;fa[u][0]=f;dee[u]=dee[f]+1;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if (v==f || ins[v]) continue;
		dfs(v,u);p=1;
	}
	if (!p) Q.push(u),vis[u]=1;
}
int lca(int a,int b) {
	if (dee[b]<dee[a]) swap(a,b);
	for (int i=19;i>=0;i--) if (dee[fa[b][i]]>=dee[a]) b=fa[b][i];
	if (a==b) return a;
	for (int i=19;i>=0;i--) {
		if (fa[a][i]!=fa[b][i])
			a=fa[a][i],b=fa[b][i];
	}
	return fa[a][0];
}
void tup() {
	while (!Q.empty()) {
		int u=Q.front();Q.pop();
		ins[u]=1;vis[u]=0;
		aup[u]=up[u];ado[u]=down[u];
		for (int i=head[u];i!=-1;i=e[i].next) {
			int v=e[i].t;
			if (ins[v]) continue;
			up[v]+=up[u];down[v]+=down[u];
			if (!vis[v]) Q.push(v),vis[v]=1;
		}
	}
}
int main() {
	memset(head,-1,sizeof head);
	n=read();m=read();q=read();
	for (int i=1;i<=m;i++) {
		u[i]=read();v[i]=read();
		add(u[i],v[i]);
	}
	for (int i=1;i<=n;i++) if (!dfn[i]) num++,Tarjan(i,-1);
	memset(head,-1,sizeof head);
	cnt=0;
	for (int i=1;i<=m;i++) if (bl[u[i]]!=bl[v[i]]) add(bl[u[i]],bl[v[i]]);
	for (int i=1;i<=now;i++) if (!ins[i]) dfs(i,0);
	for (int i=1;i<=19;i++)
		for (int j=1;j<=now;j++)
			fa[j][i]=fa[fa[j][i-1]][i-1];
	for (int i=1,a,b;i<=q;i++) {
		a=bl[read()],b=bl[read()];
		if (kin[a]!=kin[b]) return puts("No"),0;
		if (a==b) continue;
		int c=lca(a,b);
		up[c]--;down[c]--;
		up[a]++;down[b]++;//差分
	}
	memset(ins,0,sizeof ins);
	tup();
	for (int i=1;i<=now;i++) if (aup[i] && ado[i]) return puts("No"),0;
	return puts("Yes"),0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define dd c=getchar()
int read() {int s=0,w=1;char c;while (dd,c>'9' || c<'0') if (c=='-') w=-1;while (c>='0' && c<='9') s=s*10+c-'0',dd;return w*s;}
#undef dd
const int N=2e5+7;
struct edge {
	int t,next;
}e[N<<1];
int n,m,q,cnt,num;
int head[N],u[N],v[N];
void add(int u,int t) {
	e[cnt].t=t;e[cnt].next=head[u];head[u]=cnt++;
	e[cnt].t=u;e[cnt].next=head[t];head[t]=cnt++;
}
int tp,t,now;
int low[N],dfn[N],st[N],ins[N],vis[N],bl[N],kin[N];
void Tarjan(int u,int fa) {
	low[u]=dfn[u]=++t;st[++tp]=u;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if ((i^1)==fa) continue;
		if (!dfn[v]) {
			Tarjan(v,i);
			low[u]=min(low[u],low[v]);
		}
		else if(!bl[v]) low[u]=min(low[u],dfn[v]);
	}
	if (low[u]==dfn[u]) {
		now++;kin[now]=num;int v;
		do {
			v=st[tp--];
			bl[v]=now;
		} while (v!=u);
	}
}
int dee[N],fa[N][25],up[N],down[N];
void dfs(int u,int f) {
	ins[u]=1;fa[u][0]=f;dee[u]=dee[f]+1;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if (!ins[v]) dfs(v,u);
	}
}
void findfa() {
	for (int i=1;i<=20;i++)
		for (int j=1;j<=now;j++)
			fa[j][i]=fa[fa[j][i-1]][i-1];
}
int lca(int a,int b) {
	if (dee[b]<dee[a]) swap(a,b);
	for (int i=20;i>=0;i--) if (dee[fa[b][i]]>=dee[a]) b=fa[b][i];
	if (a==b) return a;
	for (int i=20;i>=0;i--) {
		if (fa[a][i]!=fa[b][i])
			a=fa[a][i],b=fa[b][i];
	}
	return fa[a][0];
}
void dfs1(int u) {
	ins[u]=1;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if (!ins[v]) {
			dfs1(v);
			up[u]+=up[v];
			down[u]+=down[v];
		}
	}
}
int main() {
	memset(head,-1,sizeof head);
	n=read();m=read();q=read();
	for (int i=1;i<=m;i++) {
		u[i]=read();v[i]=read();
		add(u[i],v[i]);
	}
	for (int i=1;i<=n;i++) if (!dfn[i]) num++,Tarjan(i,-1);
	memset(head,-1,sizeof head);
	cnt=0;
	for (int i=1;i<=m;i++) if (bl[u[i]]!=bl[v[i]]) add(bl[u[i]],bl[v[i]]);
	for (int i=1;i<=now;i++) if (!ins[i]) dfs(i,0);
	findfa();
	for (int i=1,a,b;i<=q;i++) {
		a=bl[read()],b=bl[read()];
		if (kin[a]!=kin[b]) return puts("No"),0;
		if (a==b) continue;
		int c=lca(a,b);
		up[c]--;down[c]--;
		up[a]++;down[b]++;//差分
	}
	memset(ins,0,sizeof ins);
	for (int i=1;i<=now;i++) if (!ins[i]) dfs1(i);
	for (int i=1;i<=now;i++) if (up[i] && down[i]) return puts("No"),0;
	return puts("Yes"),0;
}


#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define dd c=getchar()
int read() {int s=0;char c;while (dd,c>'9' || c<'0');while (c>='0' && c<='9') s=s*10+c-'0',dd;return s;}
#undef dd
const int N=2e5+7;
struct edge {
	int t,next;
}e[N<<1];
int n,m,q,cnt,num;
int head[N],u[N],v[N];
void add(int u,int t) {
	e[cnt].t=t;e[cnt].next=head[u];head[u]=cnt++;
	e[cnt].t=u;e[cnt].next=head[t];head[t]=cnt++;
}
int tp,t,now;
int low[N],dfn[N],st[N],ins[N],vis[N],bl[N],kin[N];
void Tarjan(int u,int fa) {
	low[u]=dfn[u]=++t;st[++tp]=u;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if ((i^1)==fa) continue;
		if (!dfn[v]) {
			Tarjan(v,i);
			low[u]=min(low[u],low[v]);
		}
		else if(!bl[v]) low[u]=min(low[u],dfn[v]);
	}
	if (low[u]==dfn[u]) {
		now++;kin[now]=num;
		while (tp) {
			int v=st[tp--];
			bl[v]=now;
			if (v==u) break;
		}
	}
}
queue<int> Q;
int dee[N],fa[N][20],up[N],down[N];
void dfs(int u,int f) {
	int p=0;
	ins[u]=1;fa[u][0]=f;dee[u]=dee[f]+1;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if (v==f || ins[v]) continue;
		dfs(v,u);p=1;
	}
	if (!p) Q.push(u),vis[u]=1;
}
int lca(int a,int b) {
	if (dee[b]<dee[a]) swap(a,b);
	for (int i=19;i>=0;i--) if (dee[fa[b][i]]>=dee[a]) b=fa[b][i];
	if (a==b) return a;
	for (int i=19;i>=0;i--) {
		if (fa[a][i]!=fa[b][i])
			a=fa[a][i],b=fa[b][i];
	}
	return fa[a][0];
}
void tup() {
	while (!Q.empty()) {
		int u=Q.front();Q.pop();
		ins[u]=1;vis[u]=0;
		int v=fa[u][0];
		if (v==0) continue;
		up[v]+=up[u];down[v]+=down[u];
		if (!vis[v]) Q.push(v),vis[v]=1;
	}
}
void dfs1(int u) {
	ins[u]=1;
	for (int i=head[u];i;i=e[i].next) {
		int v=e[i].t;
		if (!ins[v]) {
			dfs1(v);
			up[u]+=up[v];
			down[u]+=down[v];
		}
	}
}
int main() {
	memset(head,-1,sizeof head);
	n=read();m=read();q=read();
	for (int i=1;i<=m;i++) {
		u[i]=read();v[i]=read();
		add(u[i],v[i]);
	}
	for (int i=1;i<=n;i++) if (!dfn[i]) num++,Tarjan(i,-1);
	memset(head,-1,sizeof head);
	cnt=0;
	for (int i=1;i<=m;i++) if (bl[u[i]]!=bl[v[i]]) add(bl[u[i]],bl[v[i]]);
	for (int i=1;i<=now;i++) if (!ins[i]) dfs(i,0);
	for (int i=1;i<=19;i++)
		for (int j=1;j<=now;j++)
			fa[j][i]=fa[fa[j][i-1]][i-1];
	for (int i=1,a,b;i<=q;i++) {
		a=bl[read()],b=bl[read()];
		if (kin[a]!=kin[b]) return puts("No"),0;
		if (a==b) continue;
		int c=lca(a,b);
		up[c]--;down[c]--;
		up[a]++;down[b]++;//差分
	}
	memset(ins,0,sizeof ins);
	for (int i=1;i<=n;i++) if (!ins[i]) dfs1(i);
	for (int i=1;i<=now;i++) if (up[i] && down[i]) return puts("No"),0;
	return puts("Yes"),0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define dd c=getchar()
int read() {int s=0,w=1;char c;while (dd,c>'9' || c<'0') if (c=='-') w=-1;while (c>='0' && c<='9') s=s*10+c-'0',dd;return w*s;}
#undef dd
const int N=2e5+7;
struct edge {
	int t,next;
}e[N<<1];
int n,m,q,cnt,num;
int head[N],u[N],v[N];
void add(int u,int t) {
	e[cnt].t=t;e[cnt].next=head[u];head[u]=cnt++;
	e[cnt].t=u;e[cnt].next=head[t];head[t]=cnt++;
}
int tp,t,now;
int low[N],dfn[N],st[N],ins[N],vis[N],bl[N],kin[N];
void Tarjan(int u,int fa) {
	low[u]=dfn[u]=++t;st[++tp]=u;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if ((i^1)==fa) continue;
		if (!dfn[v]) {
			Tarjan(v,i);
			low[u]=min(low[u],low[v]);
		}
		else if(!bl[v]) low[u]=min(low[u],dfn[v]);
	}
	if (low[u]==dfn[u]) {
		now++;kin[now]=num;int v;
		do {
			v=st[tp--];
			bl[v]=now;
		} while (v!=u);
	}
}
int dee[N],fa[N][25],up[N],down[N];
void dfs(int u,int f) {
	ins[u]=1;fa[u][0]=f;dee[u]=dee[f]+1;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if (!ins[v]) dfs(v,u);
	}
}
void findfa() {
	for (int i=1;i<=20;i++)
		for (int j=1;j<=now;j++)
			fa[j][i]=fa[fa[j][i-1]][i-1];
}
int lca(int a,int b) {
	if (dee[b]<dee[a]) swap(a,b);
	for (int i=20;i>=0;i--) if (dee[fa[b][i]]>=dee[a]) b=fa[b][i];
	if (a==b) return a;
	for (int i=20;i>=0;i--) {
		if (fa[a][i]!=fa[b][i])
			a=fa[a][i],b=fa[b][i];
	}
	return fa[a][0];
}
void dfs1(int u) {
	ins[u]=1;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if (!ins[v]) {
			dfs1(v);
			up[u]+=up[v];
			down[u]+=down[v];
		}
	}
}
int main() {
	memset(head,-1,sizeof head);
	n=read();m=read();q=read();
	for (int i=1;i<=m;i++) {
		u[i]=read();v[i]=read();
		add(u[i],v[i]);
	}
	for (int i=1;i<=n;i++) if (!dfn[i]) num++,Tarjan(i,-1);
	memset(head,-1,sizeof head);
	cnt=0;
	for (int i=1;i<=m;i++) if (bl[u[i]]!=bl[v[i]]) add(bl[u[i]],bl[v[i]]);
	for (int i=1;i<=now;i++) if (!ins[i]) dfs(i,0);
	findfa();
	for (int i=1,a,b;i<=q;i++) {
		a=bl[read()],b=bl[read()];
		if (kin[a]!=kin[b]) return puts("No"),0;
		if (a==b) continue;
		int c=lca(a,b);
		up[c]--;down[c]--;
		up[a]++;down[b]++;//差分
	}
	memset(ins,0,sizeof ins);
	for (int i=1;i<=now;i++) if (!ins[i]) dfs1(i);
	for (int i=1;i<=now;i++) if (up[i] && down[i]) return puts("No"),0;
	return puts("Yes"),0;
}//hhh3


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define dd c=getchar()
int read() {int s=0,w=1;char c;while (dd,c>'9' || c<'0') if (c=='-') w=-1;while (c>='0' && c<='9') s=s*10+c-'0',dd;return w*s;}
#undef dd
const int N=2e5+7;
struct edge {
	int t,next;
}e[N<<1];
int n,m,q,cnt,num;
int head[N],u[N],v[N];
void add(int u,int t) {
	e[cnt].t=t;e[cnt].next=head[u];head[u]=cnt++;
	e[cnt].t=u;e[cnt].next=head[t];head[t]=cnt++;
}
int tp,t,now;
int low[N],dfn[N],st[N],ins[N],vis[N],bl[N],kin[N];
void Tarjan(int u,int fa) {
	low[u]=dfn[u]=++t;st[++tp]=u;
	for (int i=head[u];i!=-1;i=e[i].next) {
		int v=e[i].t;
		if ((i^1)==fa) continue;
		if (!dfn[v]) {
			Tarjan(v,i);
			low[u]=min(low[u],low[v]);
		}
		else if(!bl[v]) low[u]=min(low[u],dfn[v]);
	}
	if (low[u]==dfn[u]) {
		now++;kin[now]=num;int v;
		do {
			v=st[tp--];
			bl[v]=now;
		} while (v!=u);
	}
}
int dee[N],fa[N][25],up[N],down[N];
void dfs(int x,int f){
	ins[x]=1;
	for (int i=head[x];i;i=e[i].next)
		if (e[i].t!=f){
			fa[e[i].t][0]=x;
			dee[e[i].t]=dee[x]+1;
			dfs(e[i].t,x);
		}
}
inline int LCA(int x,int y){
	if (dee[x]<dee[y]) swap(x,y);
	for (int i=20;~i;--i) if (dee[fa[x][i]]>=dee[y]) x=fa[x][i];
	if (x==y) return x;
	for (int i=20;~i;--i) if (fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void dfs1(int x){
	ins[x]=1;
	for (int i=head[x];i;i=e[i].next)
		if (!ins[e[i].t]){
			dfs1(e[i].t);
			down[x]+=down[e[i].t];
			up[x]+=up[e[i].t];
		}
}
int main(){
	memset(head,-1,sizeof head);
	n=read(),m=read();q=read();
	for (int i=1;i<=m;++i){
		u[i]=read(),v[i]=read();
		add(u[i],v[i]);
	}
	for (int i=1;i<=n;++i) if (!dfn[i]) Tarjan(i,-1);
	cnt=0;
	memset(head,-1,sizeof head);
	for (int i=1;i<=m;++i)
		if (bl[u[i]]!=bl[v[i]]) add(bl[u[i]],bl[v[i]]);
	memset(ins,0,sizeof ins);
	for (int i=1;i<=now;++i) if (!ins[i])	dee[i]=1,dfs(i,0);
	for (int i=1;i<=20;++i)
		for (int j=1;j<=now;++j)
			fa[j][i]=fa[fa[j][i-1]][i-1];
	for (int x,y;q;--q){
		x=bl[read()];
		y=bl[read()];
		if (x==y) continue;
		int t=LCA(x,y);
		++down[y],--down[t];
		++up[x],--up[t];
	}
	memset(ins,0,sizeof ins);
	for (int i=1;i<=now;++i) if (!ins[i]) dfs1(i);
	for (int i=1;i<=now;++i) if (up[i] && down[i]) return puts("No"),0;
	return puts("Yes"),0;
}