#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using PII = pair; using PDD = pair; using PLL = pair; using VPII = vector; template using VT = vector; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back template inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;} template inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;} const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; //超点数や流量がめっちゃ大きいときは Dinic!! //蟻本P190~ class FordFulkerson { struct edge { int to, rev; //行き先,逆辺(のid) long long cap; //容量 edge(int _to, int _rev, long long _cap) { this->to = _to; this->rev = _rev; this->cap = _cap; } }; private: vector> G; vector used; long long dfs(int v, int t, long long f) { if (v == t) return f; used[v] = true; for (auto &&el : G[v]) { if (used[el.to] || el.cap <= 0) { continue; } long long d = dfs(el.to, t, min(f, el.cap)); if (d > 0) { el.cap -= d; G[el.to][el.rev].cap += d; return d; } } return 0; } public: FordFulkerson() {} FordFulkerson(int n) { G.resize(n); used.resize(n, false); } void add_edge(int from, int to, long long cap) { G[from].emplace_back(edge(to, G[to].size(), cap)); G[to].emplace_back(edge(from, G[from].size() - 1, 0)); } long long max_flow(int s, int t) { if (s == t) return 0; long long flow = 0; while (1) { fill(begin(used), end(used), false); long long f = dfs(s, t, LLINF); if (f == 0) return flow; flow += f; } } }; const int MAX = 150; const int SIZE = 115; FordFulkerson ff(MAX * MAX); int N; PII ip(int n) { return MP(n / SIZE, n % SIZE); } int pi(PII p) { return p.first * SIZE + p.second; } int pi(int r, int c) { return pi(MP(r, c)); } int main(void) { const int s = MAX * MAX - 1, t = s - 1; scanf("%d", &N); //各格子点 -> t REP(i, SIZE)REP(j, SIZE) ff.add_edge(pi(i, j) + SIZE, t, 1); REP(i, N) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); // s -> マッチ棒(棒はidxで表す) ff.add_edge(s, i + 1, 1); // マッチ棒 -> 棒の2つの頂点 ff.add_edge(i + 1, pi(a, b) + SIZE, 1); ff.add_edge(i + 1, pi(c, d) + SIZE, 1); } cout << (ff.max_flow(s, t) == N ? "YES" : "NO") << endl; }