#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; class UnionFind{ int cnt; vector par, rank, size; public: UnionFind(){} UnionFind(int _n):cnt(_n), par(_n), rank(_n), size(_n, 1){ for(int i=0;i<_n;++i) par[i]=i; } int find(int k){ return (k==par[k])?k:(par[k]=find(par[k])); } int operator[](int k){ return find(k); } int getSize(int k){ return size[find(k)]; } void unite(int x, int y){ x = find(x); y = find(y); if(x==y) return; --cnt; if(rank[x] < rank[y]){ par[x] = y; size[y] += size[x]; }else{ par[y] = x; size[x] += size[y]; if(rank[y] == rank[x]) ++rank[x]; } } int count(){ return cnt; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vi r0, c0, r1, c1; r0 = c0 = r1 = c1 = vi(N); vi X, Y; map p2i; vi u(N), v(N); rep(i, N) { cin >> r0[i] >> c0[i] >> r1[i] >> c1[i]; pii a = mp(r0[i], c0[i]), b = mp(r1[i], c1[i]); for(auto p : {a,b}) { if(!p2i.count(p)) { int m = sz(p2i); p2i[p] = m; } } u[i] = p2i[a], v[i] = p2i[b]; } const int M = sz(p2i); UnionFind uf(M); rep(i, N) uf.unite(u[i], v[i]); vi deg(M); rep(i, N) { deg[uf[u[i]]]++; deg[uf[v[i]]]++; } string ans = "YES"; rep(i, M) { if(deg[uf[i]] > 2*uf.getSize(i))ans = "NO"; } cout << ans << endl; }