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 ≤ AN; 1 ≤ BN; AB), 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个关系,每个关系(a b)告诉你,a比b水平高,问你最后有多少人水平是可以确定的。
思路:刚开始一开这题意就莽拓扑排序,后来发现不对,(想着如果入队多个,说明无序,入队一个就有序,简直睿智)
其实是用floyd计算传递闭包,最后看对每个人是否关系都确定了。 (因为我图中只记录了,谁比谁等级高,所以闭包出来,也只有该点是否比其他点等级高,例如 maps【a】【b】,显然缺少一种别点比他高的情况,其实就是maps【b】【a】)
 #include<cstdio>
#include<iostream> int maps[][]; int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int j=; j<=m; j++)
{
int u,v;
scanf("%d%d",&u,&v);
maps[u][v] = ;
}
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
maps[i][j] |= maps[i][k] && maps[k][j];
}
}
}
int num=n;
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// {
// printf("%d ",maps[i][j]);
// }
// puts("");
// }
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(j == i)continue;
if(!maps[i][j] && !maps[j][i])
{
num--;
break;
}
}
}
printf("%d\n",num);
}
												

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

  1. Cow Contest POJ - 3660 floyd传递闭包

    #include<iostream> #include<cstring> using namespace std; ,INF=0x3f3f3f3f; int f[N][N]; ...

  2. POJ 3660 Floyd传递闭包

    题意:牛有强弱,给出一些牛的强弱的胜负关系,问可以确定几头牛的排名. 思路: Floyd传递闭包 // by SiriusRen #include <bitset> #include &l ...

  3. Cow Contest POJ - 3660

    题意 有n(1<=n<=100)个学生参加编程比赛. 给出m条实力信息.(1<=M<=4500) 其中每一条的格式为 A B (1<=A<=N,1<=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. Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 891  Solved: 590 ...

  6. 图论---POJ 3660 floyd 算法(模板题)

    是一道floyd变形的题目.题目让确定有几个人的位置是确定的,如果一个点有x个点能到达此点,从该点出发能到达y个点,若x+y=n-1,则该点的位置是确定的.用floyd算发出每两个点之间的距离,最后统 ...

  7. POJ 3275 Floyd传递闭包

    题意:Farmer John想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛(1 ≤ N ≤ 1,000).FJ通过比较,已经知道了M(1 ≤ M ≤ 10,000)对相对关系.每一对关系表示为&q ...

  8. POJ 3660 cow contest (Folyed 求传递闭包)

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

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

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

随机推荐

  1. Tomcat系列(5)——Tomcat配置详细部分

    Tomcat的架构图 Tomcat的组织结构 Tomcat是一个基于组件的服务器,它的构成组件都是可配置的,其中最外层的是Catalina servlet容器,其他组件按照一定的格式要求配置在这个顶层 ...

  2. C#中Dictionary的介绍

    关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionar ...

  3. Centos6.5 安装 python3.5 虚拟环境 virtualenvwrapper

    Centos6.5 安装 python3.5 虚拟环境 virtualenvwrapper 1 . 安装 python3.5 下载:https://www.python.org/ https://ww ...

  4. Ansible-----include

    什么是include 在ansible中,我们可以通过include,在一个playbook中包含另一个文件,以便实现代码的重复利用. include_tasks模块 include_tasks模块用 ...

  5. appniu踩坑

    1.pyCharm识别不到appnium-python-client 解决:新建项目注意选择环境,查看Project Interpreter中是否识别到了appnium-python-client 还 ...

  6. mvc路由报错

    1.添加新项目时,把就项目的dll一起拷贝过来.生成项目,编译通过,打开页面时报错:“找到多个与名为“Home”的控制器匹配的类型 ”,网上的解决方案是,加命名空间,解决,但是自己这边删掉bin中原来 ...

  7. Java 入门

    Java 入门 入门书籍 Java相关书籍: <Java编程思想> 算是比较经典和全面的书籍; 10章可以快速过一下,都是基本语法,不需要花太多时间. 中后段的一些章节,类型信息.泛型.容 ...

  8. 第一章 初识Mysql

    Mysql是一个开放源代码的数据库管理系统(DBMS),它是由MySQL AB 公司开发.发布并支持的. 登录 -- mysql #本地登录,默认用户root,空密码,用户为root@127.0.0. ...

  9. mysql GTID

    之前一直通过binlog主从同步,现在发现GTID这种方式,记录一下,具体可参考网上教程.感觉配置使用更为简单方便,不知实际效果如何.

  10. 高可用Redis(八):Redis主从复制

    1.Redis复制的原理和优化 1.1 Redis单机的问题 1.1.1 机器故障 在一台服务器上部署一个Redis节点,如果机器发生主板损坏,硬盘损坏等问题,不能在短时间修复完成,就不能处理Redi ...