Cow Contest POJ - 3660 floyd传递闭包

#include<iostream>
#include<cstring>
using namespace std;
const int N=110,INF=0x3f3f3f3f;
int f[N][N];
int main()
{
    int n,m;
    cin>>n>>m;
    memset(f,0x3f,sizeof f);
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        //x>y
        f[x][y]=1;
        //x<y
        f[y][x]=-1;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(f[i][k]==f[k][j]&&(f[i][k]==1||f[i][k]==-1))
                    f[i][j]=f[i][k];
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int sum=0;
        //如果能确定和其他niu的关系
        for(int j=1;j<=n;j++)
            if(f[i][j]!=INF)
                sum++;
        if(sum==n-1)
            ans++;
    }
    cout<<ans<<endl;
}

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12235813.html

时间: 2024-10-06 00:40:40

Cow Contest POJ - 3660 floyd传递闭包的相关文章

ACM: POJ 3660 Cow Contest - Floyd算法

链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Eac

POJ3660:Cow Contest(Floyd传递闭包)

Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接:http://poj.org/problem?id=3660 Description: N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all k

poj 3660 Cow Contest(warshall算法)

poj 3660 Cow Contest Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the co

POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2594 Description Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploratio

POJ-3660.Cow Contest(有向图的传递闭包)

Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than other

P2419 [USACO08JAN]牛大赛Cow Contest

P2419 [USACO08JAN]牛大赛Cow Contest 海星 这题代码比较短 (哪题Floyd代码长的) 太真实了 直接上代码吧 这题就是一个经典的传递闭包问题 可以用拓扑排序啥的 不过还是Floyd简便一下 原文地址:https://www.cnblogs.com/qf-breeze/p/10473684.html

[USACO08JAN]牛大赛Cow Contest

题目链接: Cow Contest 分析: 听说是一个Floyd求传递闭包 被拓扑的标签骗了进去 首先如果整个图不连通那么显然没办法确定,因为两个连通块之间的信息没有办法传递 所以先并查集判一下 然后考虑拓扑排序,一个点能得到确定的排名当且仅当它能被之前所有入过队的点到达 代码: #include<bits/stdc++.h> #define N (300 + 10) #define M (50000 + 10) using namespace std; inline int read() {

POJ 1094 (传递闭包 + 拓扑排序)

题目链接: POJ 1094 题目大意:有 1 ~ N 个大写字母,且从 A 开始依次 N 个.再给你 M 个小于的关系,比如 A < B ,让你判断三种可能: 1.在第 i 个关系罗列之后,是否可以满足使得这 N 个字母能递增关系. 2.在第 i 个罗列之后,是否会出现矛盾,例如 A > B,而在第 i 个状态出现后,B > A ,故矛盾. 3.如果 M 个条件罗列完后都没有出现矛盾,且还无法判断 N 个字母的排列顺序,则输出  Sorted sequence cannot be de

UVA 247 电话圈 (floyd传递闭包 + dfs输出连通分量)

题意:输出所有的环: 思路:数据比较小,用三层循环的floyd传递闭包(即两条路通为1,不通为0,如果在一个环中,环中的所有点能互相连通),输出路径用dfs,递归还没有出现过的点(vis),输出并递归该点与其他点能互达的点: 1 #include <cstdio> 2 #include <vector> 3 #include <string> 4 #include <cstring> 5 #include <iostream> 6 using n