#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); } stackst; int cnt = 0; for (int j = 0; j < 2*n; j++) { if (A[rc[j]])continue; st.push(rc[j]); vectorB(10001); for (int i = 0; i < 10001; i++)B[i] = 1000; B[rc[j]] = 0; while (!st.empty() && cnt < 2) { int p = st.top(); st.pop(); 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]]) { A[X[p][i]] = true; B[X[p][i]] = B[p] + 1; st.push(X[p][i]); } else{ cnt++; } } } } if (cnt<2)cout << "YES" << endl; else cout << "NO" << endl; return 0; }