#include #include #include #include #include #include using namespace std; bool A[10101]; int main() { int n; cin >> n; vector>X(10101); vectorrc; for (int i = 0; i < n; i++) { int r0, r1, c0, c1; cin >> r0 >> c0 >> r1 >> c1; rc.push_back(r0 * 100 + c0);rc.push_back(r1 * 100 + c1); X[r0 * 100 + c0].push_back(r1 * 100 + c1); X[r1 * 100 + c1].push_back(r0 * 100 + c0); } stackst; bool flag = true; for (int j = 0; j < 2*n; j++) { int cnt = 0; if (A[rc[j]])continue; st.push(rc[j]); vectorB(10101); for (int i = 0; i < 10101; i++)B[i] = 1000; B[rc[j]] = 0; while (!st.empty() && cnt < 2) { int p = st.top(); st.pop(); if (A[p]) { cnt++; continue; } A[p] = true; for (int i = 0; i < X[p].size(); i++) { if (B[X[p][i]] == B[p] - 1)continue; if (!A[X[p][i]]) { B[X[p][i]] = B[p] + 1; st.push(X[p][i]); } else{ cnt++; if (cnt >= 2)flag = false; } } } } if (flag)cout << "YES" << endl; else cout << "NO" << endl; return 0; }