博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3660 Cow Contest (dfs)
阅读量:7135 次
发布时间:2019-06-28

本文共 2018 字,大约阅读时间需要 6 分钟。

Cow Contest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11129   Accepted: 6183

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 ≤ 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 54 34 23 21 22 5

Sample Output

2

Source

【分析】给你一些关系,例如输入u,v,表示u排在v的前面,然后问你有哪些人的排名是可以确定的。
 首先可以看出这些关系最终组成了一个有向无环图,也就是说输入u,v,u-->v;我们对于每个人查找确定排在他前面的人的个数和确定排在他后面的人的个数,
如果加起来连同他自己==n,那么说明这个人的排名确定了,那么怎么确定有多少人一定排在他前面呢?我们建两个图,一个顺序,一个逆序,然后分开找就行了。
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 10000000#define mod 10000typedef long long ll;using namespace std;const int N=605;const int M=50000;int power(int a,int b,int c){ int ans=1;while(b){ if(b%2==1){ans=(ans*a)%c;b--;}b/=2;a=a*a%c;}return ans;}int in[N],vis[N];int n,m,k;vector
vec[N],edg[N];int dfs1(int x){ vis[x]=1; int ans=1; for(int i=0;i

 

转载于:https://www.cnblogs.com/jianrenfang/p/6666156.html

你可能感兴趣的文章
Codeforces Round #133 (Div. 2) B. Forming Teams B. Forming Teams 并查集的扩张
查看>>
ECSHOP如何增加红包序列号字符
查看>>
C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 面向全国标准省市县行政数据基础之上的组织机构管理...
查看>>
给你一个承诺 - 玩转 AngularJS 的 Promise(转)
查看>>
python--sum函数--sum(axis=1)
查看>>
蓝桥杯-三羊献瑞
查看>>
继承和动态内存分配——需要为继承类定义 显式析构函数、复制构造函数和赋值运算符...
查看>>
maven "mvn不是内部或外部命令,也不是可运行的程序或批处理文件"
查看>>
深入理解JavaScript系列(31):设计模式之代理模式
查看>>
课程设计之"网络考试系统"(php、Extjs)
查看>>
《茅山后裔》全集(叶欣周铁版),MP3完整资源下载
查看>>
今天Rails都学到了啥
查看>>
Xcode3.2.6异常调试,快速定位出错行
查看>>
ASP.NET MVC显示HTML字符串
查看>>
从头到尾彻底理解KMP(转)
查看>>
使用EditText+ListView并结合TextWatcher实现输入关键字筛选数据
查看>>
二进制、十进制、十六进制相互转换
查看>>
精通MVC网站、MVVM开发模式、Razor语法
查看>>
企业IT架构介绍
查看>>
Watchdog
查看>>