[2419] Luo Valley Cattle Competition Cow Contest

Topic background

[Usaco2008 Jan]

Title 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.

FJ of N (1 <= N <= 100) cows have recently participated in the field Programming Contest :). In the game, the cows are numbered according to 1..N. Each cow programming skills are not the same, and no two cows which level par, that is to say, cows programming capabilities have a clear ranking. The entire game is divided into several rounds, each round showdown two specified number of dairy cows. If the number of cows A of programming ability in the number of cows B, (1 <= A <= N; 1 <= B <= N;! A = B), then their duel numbered cow A, always win. FJ would like to know the specific ranking cows programming ability, so he hired the cows were all the result of M (1 <= M <= 4,500) round, I hope this information you can infer as much as possible in accordance with the programming cows the ability to rank. Results of the competition is guaranteed not contradictory.

Input Format

Line 1: 2 with a space-separated integers: N and M

The first 2..M + 1 line: Each row two space-separated integers A, B, describe the cow to participate in a round of the number and the results (numbered A, is the first of each line the number of cows is the winner)

Output Format

The number of output an integer representing the ranking cows can be determined: Line 1

Sample input and output

Input # 1
5 5
4 3
4 2
3 2
1 2
2 5
Output # 1
2

Description / Tips

Output Description:

Number of cows lost to No. 2, 3, 4 cows, that her level than these three milk

Cattle are poor. The number of dairy cows 5 and lost in her hands, that is to say, her level than No. 5

Cows stronger. Thus, the ranking number of cows necessarily 4th 2, 5 numbered horizontal cows must

However, the worst. Ranked other three cows is still uncertain.

 

Solution: use floyd water over it! b is located a beat f [a] [b] = 1, if the beat i k, k defeat j, i j can defeat

           Finally, determine whether each point and other points of the outcome of the relationship. If one is not, it can not determine the rankings.

 

#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
const int N=1005;
int n,m,f[N][N],x,y,ans;
int main(){
    freopen("2419.in","r",stdin);
    freopen("2419.out","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&x,&y);
        f[x][y]=1;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(f[i][k]==1 && f[k][j]==1) f[i][j]=1;
    for(int i=1;i<=n;i++){
        int flag=1;
        for(int j=1;j<=n;j++){
            if(i==j) continue;
            if(f[i][j]==0 && f[j][i]==0) 
               { flag=0; break; }
        }
        ans+=flag;
    }
    printf("%d",years);
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11293660.html