POJ 3660 Cow Contest (dfs)
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 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ 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
Source
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 10000000
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int power(int a,int b,int c){int ans=;while(b){if(b%==){ans=(ans*a)%c;b--;}b/=;a=a*a%c;}return ans;}
int in[N],vis[N];
int n,m,k;
vector<int>vec[N],edg[N];
int dfs1(int x)
{
vis[x]=;
int ans=;
for(int i=;i<vec[x].size();i++){
int v=vec[x][i];
if(!vis[v])ans+=dfs1(v);
}
return ans;
}
int dfs2(int x)
{
int ans=;
vis[x]=;
for(int i=;i<edg[x].size();i++){
int v=edg[x][i];
if(!vis[v])ans+=dfs2(v);
}
return ans;
}
int main()
{
int u,v,ans=;;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d%d",&u,&v);
vec[u].push_back(v);
edg[v].push_back(u);
}
for(int i=;i<=n;i++){
memset(vis,,sizeof vis);
int ret1=dfs1(i);
memset(vis,,sizeof vis);
int ret2=dfs2(i);
//printf("!!%d %d\n",ret1,ret2);
if(ret1+ret2==n+)ans++;
}
printf("%d\n",ans);
return ;
}
POJ 3660 Cow Contest (dfs)的更多相关文章
- POJ 3660 Cow Contest (Floyd)
http://poj.org/problem?id=3660 题目大意:n头牛两两比赛经过m场比赛后能判断名次的有几头可转 化为路径问题,用Floyd将能够到达的路径标记为1,如果一个点能 够到达剩余 ...
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
- POJ - 3660 Cow Contest(传递闭包)
题意: n个点,m条边. 若A 到 B的边存在,则证明 A 的排名一定在 B 前. 最后求所有点中,排名可以确定的点的个数. n <= 100, m <= 4500 刚开始还在想是不是拓扑 ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
- POJ 3660 cow contest (Folyed 求传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
- POJ 3660 Cow Contest(floyed运用)
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
随机推荐
- [Luogu 3701] 「伪模板」主席树
[Luogu 3701] 「伪模板」主席树 这是一道网络流,不是主席树,不是什么数据结构,而是网络流. 题目背景及描述都非常的暴力,以至于 Capella 在做此题的过程中不禁感到生命流逝. S 向 ...
- 完美解决小米pro风扇乱转的问题
新买的小米Pro顶配,发现CPU高于20%的时候就开始狂响,最后找到了解决的方法,但是不知道会有什么影响.方法如下: 在平衡模式下更改高级电源设置--->处理器电源管理--->最大出来状态 ...
- python学习笔记(六)之操作符
python中算术操作符: + - * / % ** // 注意: /:为真实除法,即对应数学中的除法,通常返回一个浮点数 //:取整除法,即取商 %:求模,即取余数 **:幂运算,这里需要注意的一点 ...
- SQL SERVER 创建远程数据库链接 mysql oracle sqlserver
遇到的坑 在连接Oracle时,因为服务器为10g 32位版本,然后在本地安装了32为10g客户端,然后一直报错[7302.7303],后来下载了12c 64位版本,安装成功后,问题解决 原因:mss ...
- 关于js闭包官方解释庖丁解牛式理解
闭包:是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分. 变量+环境 首先按这个句子主谓宾来分解.闭包是一个表达式,通常是一个函数. 这意味着第一它 ...
- 特征工程(Feature Engineering)
一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...
- Mimikatz.ps1本地执行
PS C:\Users\hacker> Get-ExecutionPolicy Restricted PS C:\Users\hacker> Set-ExecutionPolicy Unr ...
- perl中的lock
#!/usr/bin/env perl -w use strict; use threads; use threads::shared; ; print "count的起始值为:$count ...
- STM32-内存管理
转载:http://www.cnblogs.com/guozhikai/p/6031904.html #ifndef __MALLOC_H #define __MALLOC_H #include &q ...
- python实战===用python对比两张图片的不同
from PIL import Image from PIL import ImageChops def compare_images(path_one, path_two, diff_save_lo ...