#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define fst first #define snd second using ll=long long; using pii=pair;using pll=pair;using pil=pair;using pli=pair; using vs=vector;using vvs=vector;using vvvs=vector; using vb=vector;using vvb=vector;using vvvb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templateistream&operator>>(istream&is,pair&P){is>>P.fst;is>>P.snd;return is;} templateT read(){T t;cin>>t;return t;} templateostream&operator<<(ostream&o,const pair&p){return o<<'('<ostream&operator<<(ostream&o,const vector&t){o<<"{";rep(i,sz(t))o<void e_r_r(vs::iterator it,T a,Args... args){cerr<substr((*it)[0]==' ',it->length())<<" = "< par, rank, cnt; // 親の番号, 木の大きさ, 同じ親の頂点数 UnionFind(int V) : V(V), par(V), rank(V), cnt(V) { init(); } // 初期化する void init() { for (int i = 0; i < V; i++) par[i] = i; fill(rank.begin(), rank.end(), 0); fill(cnt.begin(), cnt.end(), 1); } // 木の根を求める int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } // x と y の属する集合を併合 // 併合前は違う集合だったら true を返す bool unite(int x, int y) { if ((x = find(x)) == (y = find(y))) return false; cnt[y] = cnt[x] = cnt[x] + cnt[y]; if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } return true; } // x と y が同じ集合に属するか否か bool same(int x, int y) { return find(x) == find(y); } // x と同じ集合にいる頂点数を返す int count(int x) { return cnt[find(x)]; } }; bool solve() { int n = read(); vi U(n), V(n); map P; int m = 0; rep(i, n) { int a = read(); int b = read(); int c = read(); int d = read(); if (P.count({a, b})) { U[i] = P[{a, b}]; } else { P[{a, b}] = U[i] = m++; } if (P.count({c, d})) { V[i] = P[{c, d}]; } else { P[{c, d}] = V[i] = m++; } } vpii edges; rep(i, n) { edges.emplace_back(U[i], V[i]); } UnionFind uf(m); vi unused; rep(i, n) { int u = edges[i].fst; int v = edges[i].snd; if (!uf.same(u, v)) { uf.unite(u, v); } else { unused.emplace_back(i); } } set G; forr(i, unused) { int u = edges[i].fst; int g = uf.find(u); if (G.count(g)) return false; G.insert(g); } return true; } void Main() { cout << (solve() ? "YES" : "NO") << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }