# poj-3660-cows contest（不懂待定）

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 5
4 3
4 2
3 2
1 2
2 5

```#include<iostream>
using namespace std ;
int main()
{
int N,M,a,b;
cin>>N>>M;
int aa={0};
while(M--)
{
cin>>a>>b;
aa[a][b]=1;
}

for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
{
if(aa[j][i]&&aa[i][k])
aa[j][k]=1;
}
int ans=0;
for(int i=1;i<=N;i++)
{
int tmp=0;
for(int j=1;j<=N;j++)
tmp+=aa[i][j]+aa[j][i];
if(tmp==N-1)ans++;

}

cout<<ans<<endl;
return 0;
}```

0 条评论

• ### poj-1207 THE 3n+1 problem

Problems in Computer Science are often classified as belonging to a certain clas...

• ### poj-1007-DNA Sorting

One measure of ``unsortedness'' in a sequence is the number of pairs of entries ...

• ### poj-1163-The Triangle

Figure 1 shows a number triangle. Write a program that calculates the highest ...

• ### POJ--3321 Apple Tree(树状数组+dfs(序列)）

Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2...

• ### [LeetCode] 122. Best Time to Buy and Sell Stock II

【原题】 Say you have an array for which the ith element is the price of a given s...

• ### 【编程练习】poj1068

Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in...

• ### HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)

Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/...

• ### Leercode 35 Search Insert Position

Given a sorted array and a target value, return the index if the target is foun...

• ### 【 Gym - 101138J 】Valentina and the Gift Tree(树链剖分)

n个节点的一棵树，每个节点的权值为g，q个询问，树上的节点U-V，求U到V的路径的最大子段和。

• ### String Problem（KMP+最小表示法）- HDU 3374

Give you a string with length N, you can generate N strings by left shifts. For ...

### 活动推荐 