zoukankan      html  css  js  c++  java
  • P2419 [USACO08JAN]Cow Contest S

    传递闭包裸题。

    如果一头奶牛和其他(n-1)头奶牛的大小关系都确定了,那么该奶牛的排名可唯一确定。

    或者说,比它强的奶牛的数量加上比它弱的奶牛的数量等于(n-1),就可唯一确定该奶牛的名次。

    const int N=110;
    bool g[N][N];
    int n,m;
    
    void floyd()
    {
        for(int k=1;k<=n;k++)
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    g[i][j] |= g[i][k] & g[k][j];
    }
    
    int main()
    {
        cin>>n>>m;
    
        while(m--)
        {
            int a,b;
            cin>>a>>b;
            g[a][b]=true;
        }
    
        floyd();
    
        int res=0;
        for(int i=1;i<=n;i++)
        {
            int cnt=0;
            for(int j=1;j<=n;j++)
                if(g[i][j] || g[j][i])
                    cnt++;
            if(cnt == n-1) res++;
        }
        cout<<res<<endl;
        //system("pause");
        return 0;
    }
    
    
  • 相关阅读:
    HDU 4801 Pocket Cube
    HDU 5008 Boring String Problem(后缀数组+二分)
    2-Sat问题
    后缀数组
    树形DP
    图论
    SRM 628 DIV2
    组合博弈
    Github使用笔记
    VS2010+OpenCV配置
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14671138.html
Copyright © 2011-2022 走看看