zoukankan      html  css  js  c++  java
  • (2sat) hdu 3062

    http://wenku.baidu.com/link?url=xo0rr2Euamxkz3WOs7Nq66hZ4vrYfRQ3FWw98Z-fy37O8fOOBLUOnNpFNfS6WtfrAIUGZG2coxcrZhIqrDsFmLP1PboOr3XIGq9QFwn1b67

     

    Party

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 4768    Accepted Submission(s): 1563


    Problem Description
    有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席。在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在聚会上的。有没有可能会有n 个人同时列席?
     
    Input
    n: 表示有n对夫妻被邀请 (n<= 1000)
    m: 表示有m 对矛盾关系 ( m < (n - 1) * (n -1))

    在接下来的m行中,每行会有4个数字,分别是 A1,A2,C1,C2 
    A1,A2分别表示是夫妻的编号 
    C1,C2 表示是妻子还是丈夫 ,0表示妻子 ,1是丈夫
    夫妻编号从 0 到 n -1 
     
    Output
    如果存在一种情况 则输出YES 
    否则输出 NO 
     
    Sample Input
    2 1 0 1 1 1
     
    Sample Output
    YES
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  3060 3063 3064 3065 3067 
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<set>
    #include<stack>
    using namespace std;
    vector<int> e[2010];
    stack<int> s;
    int n,m;
    int Dfs[2010],use[1010],low[1010],isstack[1010];
    int top,newflag;
    void init()
    {
        memset(Dfs,0,sizeof(Dfs));
        memset(use,0,sizeof(use));
        memset(low,0,sizeof(low));
        memset(isstack,0,sizeof(isstack));
        for(int i=0;i<2*n;i++)
            e[i].clear();
        while(!s.empty())
            s.pop();
    }
    void tarjan(int u)
    {
        Dfs[u]=low[u]=++top;
        isstack[u]=1;
        s.push(u);
        for(int i=0;i<e[u].size();i++)
        {
            int v=e[u][i];
            if(!Dfs[v])
            {
                tarjan(v);
                low[u]=min(low[u],low[v]);
            }
            else if(isstack[v])
                low[u]=min(low[u],Dfs[v]);
        }
        if(Dfs[u]==low[u])
        {
            newflag++;
            int x;
            do
            {
                x=s.top();
                s.pop();
                use[x]=newflag;
                isstack[x]=0;
            }while(x!=u);
        }
    }
    int main()
    {
        int a,b,c,d;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            init();
            for(int i=1;i<=m;i++)
            {
                scanf("%d%d%d%d",&a,&b,&c,&d);
                int u,v;
                u=2*a+c,v=2*b+d;
                e[u].push_back(v^1);
                e[v].push_back(u^1);
            }
            for(int i=0;i<2*n;i++)
            {
                if(!Dfs[i])
                    tarjan(i);
            }
            bool flag=true;
            for(int i=0;i<n;i++)
            {
                if(use[2*i]==use[(2*i)^1])
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                printf("YES
    ");
            }
            else
                printf("NO
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    LeetCode 258 Add Digits
    LeetCode 231 Power of Two
    LeetCode 28 Implement strStr()
    LeetCode 26 Remove Duplicates from Sorted Array
    LeetCode 21 Merge Two Sorted Lists
    LeetCode 20 Valid Parentheses
    图形处理函数库 ImageTTFBBox
    php一些函数
    func_get_arg(),func_get_args()和func_num_args()的用法
    人生不是故事,人生是世故,摸爬滚打才不会辜负功名尘土
  • 原文地址:https://www.cnblogs.com/water-full/p/4531399.html
Copyright © 2011-2022 走看看