#include #include #include #include #include using namespace std; typedef struct __match { int x1; int y1; int x2; int y2; } Match; bool touches(Match a, Match b) { if ((a.x1 == b.x1 && a.y1 == b.y1) || (a.x1 == b.x1 && b.y2 == b.y2) || (a.x2 == b.x2 && a.y1 == b.y1) || (a.x2 == b.x2 && a.y2 == b.y2) ) { return true; } else { return false; } } 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; } vector> connect(n); for (int i = 0; i < n; i++) { Match m1 = matches[i]; for (int j = i + 1; j < n; j++) { Match m2 = matches[j]; if (touches(m1, m2)) { connect[i].insert(j); connect[j].insert(i); } } } bool updates = true; do { updates = false; for (int i = 0; i < n; i++) { if (connect[i].size() == 1) { int tmp = *(connect[i].begin()); connect[i].erase(tmp); connect[tmp].erase(i); updates = true; } } } while (updates); int maxi = 0; for (int i = 0; i < n; i++) { maxi = max(maxi, (int)connect[i].size()); } cout << (maxi > 1 ? "NO" : "YES") << endl; return 0; }