2014/7/15
我是彩笔系列
我是一只小青蛙,wawawa.
我是彩笔, l = l<<1 +m 和l = (l<<1)+m;分不清,傻傻的wawawa.
PS:一开始不知道哪错了...去网上找题解,全是高大上邻接表...渣渣表示一眼看不懂..所以还是把这道水题的代码贴了出来.
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<climits>
#include<vector>
using namespace std;
#define f(x,y,i) for(int i = x;i < y; i++)
#define F(x,y,i) for(int i = x; i <= y; i++)
#define lson pos<<1,l,mid
#define rson pos<<1|1,mid+1,r
#define sc(n) scanf("%d",&n)
#define pr(n) printf("%d\n",n)
#define met(n,m) memset(n, m, sizeof(n))
const int N=5000;
vector<int>q[N];
int n, m, cnt;
int ans[N];
int s[N];
int l,l1,r,r1;
void init()
{
f(0,N,i)q[i].clear();
met(s,0);
}
void read()
{
sc(m);
while(m--)
{
scanf("%d%d%d%d",&l,&r,&l1,&r1);
l=(l<<1)+l1;
r=(r<<1)+r1;
q[r].push_back(l^1);
q[l].push_back(r^1);
}
}
bool dfs(int v)
{
if(s[v] == 1)return true;
if(s[v] == 2)return false;
s[v]=1;
s[v^1]=2;
ans[cnt++] = v;
int len =q[v].size();
f(0,len,i)
{
if(!dfs(q[v][i]))return false;
}
return true;
}
bool solve()
{
f(0,n,i)
{
if(s[i])continue;
cnt = 0;
if(!dfs(i))
{
f(0,cnt,j)
{
s[ans[j]] =0;
s[ans[j]^1]=0;
}
if(!dfs(i^1))return false;
}
}
return true;
}
int main()
{
while(~sc(n))
{
n<<=1;
init();
read();
if(solve())printf("YES\n");
else printf("NO\n");
}
return 0;
}