#include using namespace std; struct iostream_init_struct { iostream_init_struct() { std::cin.tie(0); std::cin.sync_with_stdio(false); } } iostream_init; #include template class union_find { private: std::unordered_map parent_; std::unordered_map loop_; public: TYPE find(TYPE x) { auto itr = parent_.find(x); if (itr == parent_.end()) return x; else { TYPE parent = itr->second; return parent_[x] = find(parent); } } // returns num of loop int unite(TYPE x, TYPE y) { TYPE x_parent = find(x); TYPE y_parent = find(y); if (x_parent == y_parent) { return loop_[x_parent] += 1; } parent_[y_parent] = x_parent; int ret = loop_[x_parent] += loop_[y_parent]; loop_.erase(y_parent); return ret; } bool is_same(TYPE x, TYPE y) { return find(x) == find(y); } }; class PairHash { public: size_t operator()(const pair& obj) const { return obj.first * 1000 + obj.second; } }; int main(void) { union_find, PairHash> m; int N; cin >> N; for (int i = 0; i < N; ++i) { int r0, c0, r1, c1; cin >> r0 >> c0 >> r1 >> c1; if (m.unite(make_pair(r0, c0), make_pair(r1, c1)) >= 2) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }