Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7690   Accepted: 4288

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 competitors.

The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ NA ≠ B), then cow A will always beat cow B.

Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.

Input

* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined
 

Sample Input

5 5
4 3
4 2
3 2
1 2
2 5

Sample Output

2

刚才学了下闭包传递,简单来说就是用Floyd来求两点是否连通。这题里,如果一点的入度加上出度等于N-1,那么就可确定这点的等级,因为除了它自己之外的所有节点要么在它之前要么在它之后,不管它前面的节点后后面的节点怎么排序,都不会影响到它。
 #include <iostream>
#include <cstdio>
using namespace std; const int SIZE = ;
int N,M;
int IN[SIZE],OUT[SIZE];
bool G[SIZE][SIZE]; int main(void)
{
int from,to;
int ans; while(scanf("%d%d",&N,&M) != EOF)
{
fill(&G[][],&G[N][N],false);
for(int i = ;i <= N;i ++)
IN[i] = OUT[i] = ; for(int i = ;i < M;i ++)
{
scanf("%d%d",&from,&to);
G[from][to] = true;
} for(int k = ;k <= N;k ++)
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
G[i][j] = G[i][j] || G[i][k] && G[k][j];
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
if(G[i][j])
{
IN[j] ++;
OUT[i] ++;
} ans = ;
for(int i = ;i <= N;i ++)
if(IN[i] + OUT[i] == N - )
ans ++;
printf("%d\n",ans);
} return ;
}

POJ 3660 Cow Contest (闭包传递)的更多相关文章

  1. POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)

    POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...

  2. POJ 3660 Cow Contest

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  3. POJ 3660 Cow Contest 传递闭包+Floyd

    原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  4. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  5. POJ - 3660 Cow Contest 传递闭包floyed算法

    Cow Contest POJ - 3660 :http://poj.org/problem?id=3660   参考:https://www.cnblogs.com/kuangbin/p/31408 ...

  6. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  7. ACM: POJ 3660 Cow Contest - Floyd算法

    链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Descri ...

  8. poj 3660 Cow Contest(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

  9. POJ 3660 Cow Contest (floyd求联通关系)

    Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...

随机推荐

  1. mysql index的长度限制

    在InnoDB Storage Engine中单独一个列的最大的索引长度为767bytes,utf8字符集中,一个字符占3个字节,所以如果列的类型为char,那么要想在此列上建立索引,此列最多只能有2 ...

  2. 使用sql访问EXECL文件

    --使用sql语句打开访问EXECL文件 --SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDat ...

  3. 重学HTML

    http://www.imooc.com/learn/9 1.em/strong 如果想在一段话中特别强调某几个文字,这时候就可以用到<em>或<strong>标签. 但两者在 ...

  4. 转载:rebar和erlang

    使用rebar生成erlang release 并进行热代码升级 http://blog.sina.com.cn/s/blog_6530ad590100wmkn.html 使用rebar工具开发erl ...

  5. SQL SERVER:开窗函数 SUM() OVER() 数据统计中一例使用

    由于前一段时间胃痛,导致博客园博客都停更了一个月左右.近几天,胃病终于稍微有所好转,决定重新写博文. 前几天,有个朋友刚好问到本人有关 SQL 语句,大致是原表有两列,分别为月份.月份销售额,而需要一 ...

  6. PropertiesUtil 读取配置文件工具类

    package org.konghao.basic.util; import java.io.FileInputStream; import java.io.FileNotFoundException ...

  7. JS 去字符串空格

    str为要去除空格的字符串:去除所有空格: str = str.replace(/\s+/g,""); 去除两头空格: str = str.replace(/^\s+|\s+$/g ...

  8. FluentData官方文档翻译

    开始 要求 .NET 4.0. 支持的数据库 MS SQL Server using the native .NET driver. MS SQL Azure using the native .NE ...

  9. COM组件入门(一)

    近期须要用到COM组件的知识,看了看COM编程指南,感觉还不错.把我的学习心得记录下来.这是我依据教程写的demo StopWatch接口实现部分,接口部分我的项目是动态库,主要源代码例如以下: 完整 ...

  10. 减少远程ssh的延迟

    今天搞了个很廉价的vps,ssh上去之后操作卡顿得不行,有时候输入一行命令后需要等五六秒才显示出来,蛋疼得不行. 然后想找一个解决方案,先是看到了mosh. 搜索了下教程,看了下说明,因为我这个廉价的 ...