#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- template class MaxFlow_Ford { public: struct edge { int to,reve;V cap;}; static const int MV = 20500; vector E[MV]; int vis[MV]; void add_edge(int x,int y,V cap,bool undir=false) { E[x].push_back((edge){y,(int)E[y].size(),cap}); E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0}); } V dfs(int from,int to,V cf) { V tf; if(from==to) return cf; vis[from]=1; FORR(e,E[from]) if(vis[e.to]==0 && e.cap>0 && (tf = dfs(e.to,to,min(cf,e.cap)))>0) { e.cap -= tf; E[e.to][e.reve].cap += tf; return tf; } return 0; } V maxflow(int from, int to) { V fl=0,tf; while(1) { ZERO(vis); if((tf = dfs(from,to,numeric_limits::max()))==0) return fl; fl+=tf; } } }; int N; int X1[101],X2[101],Y1[101],Y2[101]; MaxFlow_Ford mf; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(y,104) FOR(x,104) mf.add_edge(y*105+x,105*105,1); FOR(i,N) { cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i]; mf.add_edge(105*106,106*106+i,1); mf.add_edge(106*106+i,X1[i]*105+Y1[i],1); mf.add_edge(106*106+i,X2[i]*105+Y2[i],1); } x = mf.maxflow(105*106,105*105); if(x==N) cout<<"YES"<