#include #include #include #include #include #include #include using namespace std; typedef pair PII; typedef struct __match { int x1; int y1; int x2; int y2; } Match; bool touches(Match m, int x, int y) { if ((m.x1 == x && m.y1 == y) || (m.x2 == x && m.y2 == y)) { return true; } else { return false; } } bool touches(Match a, Match b) { if (touches(a, b.x1, b.y1) || touches(a, b.x2, b.y2)) { return true; } else { return false; } } void show(map> mps) { printf("----------\n"); for (auto ppp : mps) { PII p = ppp.first; printf("(%d, %d): ", p.first, p.second); for (auto e : ppp.second) { printf("%d ", e); } printf("\n"); } } int main() { int n, a, b, c, d; cin >> n; vector matches(n); for (int i = 0; i < n; i++) { cin >> a >> b >> c >> d; Match m = {a, b, c, d}; matches[i] = m; } map> have_match; for (int i = 0; i < n; i++) { Match m = matches[i]; have_match[make_pair(m.x1, m.y1)].insert(i); have_match[make_pair(m.x2, m.y2)].insert(i); } bool updates = true; do { updates = false; for (auto xxx : have_match) { if (xxx.second.size() > 1) { continue; } // show(have_match); if (xxx.second.size() == 0) { have_match.erase(xxx.first); updates = true; break; } PII p = xxx.first; int idx = *(xxx.second.begin()); Match m = matches[idx]; PII q; if (p == make_pair(m.x1, m.y1)) { q = make_pair(m.x2, m.y2); } else { q = make_pair(m.x1, m.y1); } have_match[p].erase(idx); have_match[q].erase(idx); updates = true; break; } } while (updates); int maxi = 0; for (auto x : have_match) { maxi = max(maxi, (int)x.second.size()); } cout << (maxi > 2 ? "NO" : "YES") << endl; return 0; }