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

题意:给出n只奶牛,m个胜负关系,求有几只奶牛的排名可以确定?

题解:传递闭包什么的,听着很高级,其实非常滑稽,感觉自学啥的也就两分钟,其实也就是一个floyd的延伸
用floyd根据三头牛之间a-b,b-c的胜负关系来判断a-c的胜负关系,然后显然除了和自己以外,如果和其他奶牛的关系已经确定了,他的排名也就确定了
然后就写出来了 代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; int map[][],n,m; int main()
{
memset(map,-,sizeof(map));
scanf("%d%d",&n,&m);
int xx,yy;
for(int i=;i<=m;i++)
{
scanf("%d%d",&xx,&yy);
map[xx][yy]=;
map[yy][xx]=;
}
for(int i=;i<=n;i++)
{
map[i][i]=;
}
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(map[i][k]==&&map[k][j]==)
{
map[i][j]=;
}
if(!map[i][k]&&!map[k][j])
{
map[i][j]=;
}
}
}
}
int ans=;
for(int i=;i<=n;i++)
{
int flag=;
for(int j=;j<=n;j++)
{
if(map[i][j]==-)
{
flag=;
}
}
ans+=flag;
}
printf("%d\n",ans);
}



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

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

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

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

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

  3. POJ 3660 Cow Contest. (传递闭包)【Floyd】

    <题目链接> 题目大意: 有n头牛, 给你m对关系(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少牛的排名. 解题分析: 首先,做这道题要明确,什么叫确定牛的排名.假设 ...

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

  5. POJ 3660 Cow Contest

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

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

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

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

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

  8. POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16341   Accepted: 9146 Desc ...

  9. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

随机推荐

  1. [POJ] The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 47278   Accepted: 28608 De ...

  2. 初识python(python的安装与运行)

    python--“优雅”.“明确”.“简单”的哲学定位 一.python的安装(Windows环境下) 1.在python官网下载安装文件 python的官方网址:https://www.python ...

  3. django之管理静态文件

    管理静态文件 项目中的CSS.图片.js都是静态文件 配置静态文件 在settings 文件中定义静态内容 STATIC_URL = '/static/' STATICFILES_DIRS = [ o ...

  4. mysql导出数据库数据及表结构

    1,导出远程数据库数据到本地 mysql -A wj_sms -h192.168.1.105 -uroot -p4321 -ss -e "set NAMES 'utf8';SELECT * ...

  5. How To Install MongoDB on CentOS 6

    How To Install MongoDB on CentOS 6 Posted on January 21, 2014 by J. Mays | Updated: January 22, 2014 ...

  6. LR11中webservice协议的性能测试应用

    使用LR11对webservice协议的接口测试应用 脚本开发步骤:1.打开vuser generator,新建一个脚本,选择webservice协议:2.选择Manage Services(服务管理 ...

  7. leetcode747

    public class Solution { public int DominantIndex(int[] nums) { var list = new List<KeyValuePair&l ...

  8. MantisBT 缺陷管理系统

    简介: 公司需要一套缺陷管理系统,这种系统比较热门的有 Jira.Redmine.MantisBT 等. 这次来整理一下 MantisBT,正好公司需要,以前的文档又丢失了. 下载地址:http:// ...

  9. 4.2 最邻近规则分类(K-Nearest Neighbor)KNN算法应用

    1 数据集介绍:   虹膜     150个实例   萼片长度,萼片宽度,花瓣长度,花瓣宽度 (sepal length, sepal width, petal length and petal wi ...

  10. Elasticsearch-PHP 索引操作2

    索引操作 索引在客户端非常容易.因为关联数组很容易转换为JSON文档,索引文档只是提供正确和结构性的关联数组和调用方法. 单文档索引 当你索引你个文档时,可以自己提供一个ID,也可以让elastics ...