Luogu P2419 [USACO08JAN]牛大赛Cow Contest

Posted maomao9173

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Luogu P2419 [USACO08JAN]牛大赛Cow Contest相关的知识,希望对你有一定的参考价值。

传递闭包板子,震惊自己之前居然没学过,特此记录一下。

#include <bits/stdc++.h>
using namespace std;

const int N = 110;

int n, m, u, v, to[N][N];

int main () {
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> u >> v;
        to[u][v] = true;
    }
    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                to[i][j] = to[i][j] | (to[i][k] & to[k][j]);
                //i -直接-> j or i -间接-> j
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int tot = 0; //可确定关系数
        for (int j = 1; j <= n; ++j) {
            if (i == j) continue;
            tot += (to[i][j] | to[j][i]);
        }
        ans += (tot == n - 1);
    }
    cout << ans << endl;
} 

以上是关于Luogu P2419 [USACO08JAN]牛大赛Cow Contest的主要内容,如果未能解决你的问题,请参考以下文章

bzoj1612 / P2419 [USACO08JAN]牛大赛Cow Contest(Floyd)

P2419 [USACO08JAN]牛大赛Cow Contest

题解 P2419 [USACO08JAN]牛大赛Cow Contest

[USACO12JAN]牛联盟Bovine Alliance

luogu P1353 [USACO08JAN]跑步Running

[USACO08JAN]牛大赛Cow Contest