zoukankan      html  css  js  c++  java
  • 「日常训练」「小专题·图论」 Cow Contest (1-3)

    题意

    分析

    问题是要看出来这是个floyd闭包问题。我没看出来- -
    分析之后补充。

    代码

    // Origin:
    // Theme: Graph Theory (Basic)
    // Date: 080618
    // Author: Sam X
    
    //#include <bits/stdc++.h>
    #include <iostream>
    #include <utility>
    #include <iomanip>
    #include <cstring>
    #include <cmath>
    #define MP make_pair
    #define PB push_back
    #define fi first
    #define se second
    #define ZERO(x) memset((x), 0, sizeof(x))
    #define ALL(x) (x).begin(),(x).end()
    #define rep(i, a, b) for (int i = (a); i <= (b); ++i)
    #define per(i, a, b) for (int i = (a); i >= (b); --i)
    #define QUICKIO                  
        ios::sync_with_stdio(false); 
        cin.tie(0);                  
        cout.tie(0);
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ul;
    typedef pair<int,int> pi;
    typedef pair<int,pi> pii;
    
    int n,m;
    bool d[105][105];
    int main()
    {
        while(cin>>n>>m)
        {
            ZERO(d);
            rep(i,1,m)
            {
                int x,y; cin>>x>>y;
                d[x][y]=true;
            }
            rep(k,1,n)
                rep(i,1,n)
                    rep(j,1,n)
                        d[i][j]=d[i][j]||(d[i][k] && d[k][j]);
            int ans=0;
            rep(i,1,n)
            {
                int sum=0;
                rep(j,1,n)
                {
                    if(d[i][j]||d[j][i]) sum++;
                }
                if(sum==n-1) ans++;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    netty中Pipeline的ChannelHandler执行顺序案例详解
    Pi-设置无线
    Pi1-Centos
    gitlab升级
    ansible
    我也玩Jenkins
  • 原文地址:https://www.cnblogs.com/samhx/p/9652054.html
Copyright © 2011-2022 走看看