HDU3062 Party (2-SAT)

Posted bingoyes

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;

以上是关于HDU3062 Party (2-SAT)的主要内容,如果未能解决你的问题,请参考以下文章

HDU3062 Party (2-SAT)

[HDU3062]Party

HDU3062(2-SAT)

二分+2-sat——hdu3062

two-sat hdu3062 UVALive 3211

HDU 3062 Party