#include #include #include #include #include #include using namespace std; 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(vector> vs) { printf("----------\n"); for (int i = 0; i < vs.size(); i++) { printf("%2d: ", i); for (auto e : vs[i]) { printf("%2d ", 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; } 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++) { int next1 = 0; int next2 = 0; Match m = matches[i]; for (auto e : connect[i]) { if (touches(matches[e], m.x1, m.y1)) { next1++; } else { next2++; } } maxi = max({maxi, next1, next2}); } cout << (maxi > 1 ? "NO" : "YES") << endl; return 0; }