#include #include #include #include #include #include using namespace std; bool A[10001]; int main() { int n; cin >> n; vector>X(10001); X.reserve(n); 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); } stack>st; int cnt = 0; for (int j = 0; j < 2*n; j++) { if (A[rc[j]])continue; st.push(make_pair(rc[j],0)); vectorB(10001); for (int i = 0; i < 10001; i++)B[i] = 1000; B[rc[j]] = 0; while (!st.empty() && cnt < 2) { pair p = st.top(); st.pop(); if (A[p.first])continue; A[p.first] = true; for (int i = 0; i < X[p.first].size(); i++) { if (B[X[p.first][i]] == p.second - 1)continue; if (!A[X[p.first][i]]) { B[X[p.first][i]] = p.second + 1; st.push(make_pair(X[p.first][i], B[X[p.first][i]])); } else{ cnt++; } } } } if (cnt<2)cout << "YES" << endl; else cout << "NO" << endl; return 0; }