HDU3062 Party (2-SAT)
没注意边数T了N遍的我真是弱啊
const int N = 2007;
int n;
struct Edge{
int nxt,pre;
}e[1000007];
int cntEdge,head[N];
inline void add(int u,int v){
e[++cntEdge] = (Edge){head[u], v}, head[u] = cntEdge;
}
int dfn[N],dfnIndex,low[N],vis[N];
int sta[N],top;
int bcc[N],bccIndex;
inline void Tarjan(int u){
dfn[u] = low[u] = ++dfnIndex;
vis[u] = true;
sta[++top] = u;
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(!dfn[v]){
Tarjan(v);
low[u] = Min(low[u], low[v]);
}
else if(vis[v]){
low[u] = Min(low[u], dfn[v]);
}
}
if(dfn[u] == low[u]){
++bccIndex;
do{
bcc[sta[top]] = bccIndex;
vis[sta[top]] = false;
}while(sta[top--] != u);
}
}
inline bool Judge(){
R(i,1,n){
if(bcc[i<<1] == bcc[i<<1|1])
return false;
}
return true;
}
int main(){
int m;
while(~scanf("%d%d", &n, &m)){
cntEdge = 0;
n <<= 1;
R(i,1,n){
head[i] = 0,
dfn[i] = 0,
low[i] = 0,
vis[i] = false;
}
n >>= 1;
R(i,1,m){
int a,b,c,d;
io >> a >> b >> c >> d;
a = (a<<1) + c;
b = (b<<1) + d;
add(a, b ^ 1);
add(b, a ^ 1);
}
n <<= 1;
R(i,1,n){
if(!dfn[i])
Tarjan(i);
}
n >>= 1;
if(Judge() == true)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}