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个关系,每次输入的x,y代表x胜过y,求出能够确定当前奶牛和其他所有奶牛的关系的奶牛有几头。
思路:对于每两个奶牛之间有三种关系, 1.没关系 2. a胜过b 3. a输给b,我们用dis[i][j] 代表第i只奶牛和第j只奶牛的关系。我们首先可以对开始输入的奶牛的关系建图,之后用floyed跑一遍图,遍历完所有点点之间的关系,最后判断每一个点,若与其他n-1个点都有关系则ans++
 #include<iostream>
#include<algorithm>
#include<vector>
#include<queue> using namespace std;
const int INF = 0x3f3f3f3f;
int dis[][];
int n, m;
void floyed()
{
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++) {
if ((dis[i][k] == && dis[k][j] == ) || (dis[i][k] == && dis[k][j] == ))
dis[i][j] = dis[i][k]; //判断ij之间的关系
}
}
int main()
{
ios::sync_with_stdio(false);
while (cin >> n >> m) {
memset(dis, , sizeof(dis));
for (int a, b, i = ; i <= m; i++) {
cin >> a >> b;
dis[a][b] = ;//a胜b
dis[b][a] = ;//a输给b
}
floyed();
int ans = ;
for (int i = ; i <= n; i++) {
int cnt = ;
for (int j = ; j <= n; j++) {
if (i == j)continue;
if (dis[i][j])cnt++;
}
if (cnt == (n - ))ans++;
}
cout << ans << endl;
}
return ;
}

POJ 3660 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

    题目链接: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 传递闭包floyed算法

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

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

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

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

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

  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 (闭包传递)

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

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

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

随机推荐

  1. ipad模拟器iPadian.exe

    http://dl.pconline.com.cn/download/368140.html 苹果IPAD模拟器!让你的电脑立刻拥有IOS系统!马上变成ipad!几百个免费的扩展应用程序,能登QQ,微 ...

  2. Flask 第二篇

    Flask 中的 Render Redirect HttpResponse 1.Flask中的HTTPResponse 在Flask 中的HttpResponse 在我们看来其实就是直接返回字符串 2 ...

  3. POJ-3026_Borg Maze

    Borg Maze Time Limit: 1000MS Memory Limit: 65536K Description The Borg is an immensely powerful race ...

  4. 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server

    题目描述     In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...

  5. HDU_1005:Number Sequence

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  6. UVA_10055:Hashmat the brave warrior

    Language:C++ 4.8.2 #include<stdio.h> int main(void) { long long int a, b; while(scanf("%l ...

  7. 动态设置iframe高度

    <%//动态设置iframe高度 %><script language="javascript" type="text/javascript" ...

  8. Flask学习之九 分页

    英文博客地址:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-ix-pagination 中文翻译地址:http:// ...

  9. selenium webdriver学习(四)------------定位页面元素(转)

    selenium webdriver学习(四)------------定位页面元素 博客分类: Selenium-webdriver seleniumwebdriver定位页面元素findElemen ...

  10. EC round 33 D. Credit Card 贪心

    因为到为0的点,充钱的范围都是不确定的,我们维护一个满足条件的最小值以及满足条件的最大值. 当min>d时,代表已经满足条件限制了 当a[ i ] = 0 并且 max<0,代表需要充钱, ...