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

题目意思:评定牛的等级,有n头牛,进行了m场比赛,位置在前面的是胜利的牛的编号,如果一头牛和剩下的牛都能确定等级关系,说明可以去确定该牛的等级
,求出可以确定等级的牛的个数 解题思路:这是一个利用最短路floyed算法的一个传递闭包问题,如果一个点和其余各点都确定关系了,那么这个点的等级就可以确定了。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m;
int map[200][200];
int floyd()
{
int i,j,k;
for(k=1; k<=n; k++)
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
if(map[i][k]&&map[k][j])
{
map[i][j]=1;///如果任意两个点能够通过第三个点发生关系,那么说明这两个点也是有关系的
}
}
}
int main()
{
int a,b,i,j,count,sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,0,sizeof(map));
for(i=0; i<m; i++)
{
scanf("%d%d",&a,&b);
map[a][b]=1;///可以确定关系的利用邻接矩阵记录为1
}
floyd();
count=0;
for(i=1; i<=n; i++)
{
sum=0;
for(j=1; j<=n; j++)
{
if(map[i][j]||map[j][i])
{
sum++;
}
}
if(sum==n-1)///如果一个点和其余各点的关系确定,那么这个点就可以确定等级
{
count++;
}
}
printf("%d\n",count);
}
return 0;
}

  


Cow Contest(最短路floyed传递闭包)的更多相关文章

  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(Floyd求传递闭包(可达矩阵))

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

  3. Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset

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

  4. POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )

    题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A  B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...

  5. (poj 3660) Cow Contest (floyd算法+传递闭包)

    题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...

  6. POJ-3660 Cow Contest( 最短路 )

    题目链接:http://poj.org/problem?id=3660 Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, ar ...

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

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

  8. Median Weight Bead(最短路—floyed传递闭包)

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

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

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

随机推荐

  1. Hibernate 事务不回滚

    问题:               这几天在做开发时,发现事务不回滚了,Service是用AOP加的事务,数据库是MySql, 表全部是InnoDB:   方法回滚是采用spring的手动回滚:   ...

  2. web开发问题汇总

    Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" content="wi ...

  3. Echarts+百度地图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 壹度DIY_微信小程序组件_小程序插件开发

    开源免费插件,diy特有的页面机制,搭配30+自定义组件,让你的站点每一个页面都可以完全自定义,可无缝对接任意小程序,如有疑问加入qq壹度小程序交流群:302866773:或wx:liu2417301 ...

  5. JS第一周学习笔记整理

    目录 JS正式课第一周笔记整理 JS正式课第一周笔记整理 webstorm : 代码编辑器 浏览器: 代码解析器: Git : 是一个工具;用于团队协作开发项目管理代码的工具:在工作中用git.svn ...

  6. 『Python题库 - 简答题』 Python中的基本概念 (121道)

    ## 『Python题库 - 简答题』 Python中的基本概念 1. Python和Java.PHP.C.C#.C++等其他语言的对比? 2. 简述解释型和编译型编程语言? 3. 代码中要修改不可变 ...

  7. hadoop 1.x 集群环境的搭建

    本文主要以个人工作学习总结为主,同时也为了方便更多的兴趣爱好者参与学习交流,现将具体的搭建步骤分享如下: 一.基础环境 1.1 jdk的安装与配置 Hadoop是用Java开发的,Hadoop的编译及 ...

  8. Go 入门 - Go中的复杂类型

    主要内容来自中文版的官方教程Go语言之旅 目的为总结要点 指针 Go 拥有指针.指针保存了值的内存地址. 类型 *T 是指向 T 类型值的指针.其零值为 nil. var p *int & 操 ...

  9. WPF ResourceDictionary 主题资源替换

    原文:WPF ResourceDictionary 主题资源替换 当我们需要在程序中替换主题,更换另一套背景.颜色.样式时,如何在不修改资源Key值,直接替换呢? 问题&疑问 1. Key值冲 ...

  10. 深圳Uber优步司机奖励政策(12月28日到1月3日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...