#include using namespace std; typedef long long LL; struct cww{cww(){ ios::sync_with_stdio(false);cin.tie(0); cout<inline void chmin(T &l,T r){l=min(l,r);} template inline void chmax(T &l,T r){l=max(l,r);} template istream& operator>>(istream &is,vector &v){ for(auto &it:v)is>>it; return is; } #include using namespace std; struct edge{ int flow,to,rev; }; typedef vector E; typedef vector Graph; void addedge(Graph&g,int from,int to,int f){ int x=g[from].size(); int y=g[to].size(); g[from].pb(edge{f,to,y}); g[to].pb(edge{0,from,x}); } vector bfs(Graph& G,int s){ int N = G.size(); queue que; vector dist(N,-1); dist[s] = 0; que.push(s); for(;!que.empty();que.pop()){ auto v=que.front(); for(auto& e : G[v]) if(e.flow>0&&dist[e.to]==-1){ dist[e.to] = dist[v] + 1; que.push(e.to); } } return dist; } int maxflow(Graph& G,int s,int t){ int res=0; int N = G.size(); while(true){ auto dist = bfs(G,s); if(dist[t] < 0)break; vector iter(N,0); std::function dfs=[&](int v,int f){ if(v==s)return f; for(auto &i = iter[v]; i < G[v].size(); i++){ edge &e = G[v][i]; edge &re = G[e.to][e.rev]; if(re.flow>0 && dist[v] >dist[e.to]){ int d=dfs(e.to,min(f,re.flow)); if(d>0){e.flow+=d;re.flow-=d;return d;} } } return 0; }; int f; while((f=dfs(t,114514))> 0)res+=f; } return res; } typedef pair P; int main(){ int N; cin>>N; vector

a(N),b(N); map c; REP(i,N){ cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se; c[a[i]]=0; c[b[i]]=0; } int M=0; for(auto &it:c)it.se=M++; int S=N+M; int G=S+1; Graph g(N+M+2); REP(i,N)addedge(g,S,i,1); REP(i,M)addedge(g,N+i,G,1); REP(i,N){ addedge(g,i,N+c[a[i]],1); addedge(g,i,N+c[b[i]],1); } if(maxflow(g,S,G)==N)cout<<"YES"<