[Graph theory] cattle contest

Original title Portal

Thinking


This question is not difficult, the main difficulty in bad judgment which has ranked cows can be determined, but the problem is actually very easy to solve: penetration + = N-1 out of the cow can be determined, on the contrary can not be determined.
Then, if i can beat cow cow k, k can beat cows and cows j, then i will be able to defeat the cow cows j (this is not bullshit you).
As long as no brain wave to Floyd, the degree of each node is determined and the degree to.

As an aside, the question should not be so foreign to engage ⛏? Cows open programming competition, for the hair I feel good thick irony of it QAQ?

Code


#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#define int long long
using namespace std;

int G[101][101];
int N,M,A,B,ans,tans;

signed main()
{
    scanf("%ld%ld",&N,&M);
    for(int i=1;i<=M;i++)
    {
        scanf("%ld%ld",&A,&B);
        G[A][B]=1;
    }
    for(int k=1;k<=N;k++)
        for(int i=1;i<=N;i++)
            for(int j=1;j<=N;j++)
                if(G[i][k]&&G[k][j])
                    G[i][j]=1;
    for(int i=1;i<=N;i++)
    {
        tans=0;
        for(int j=1;j<=N;j++)
        {
            tans+=G[i][j]+G[j][i];
        }
        if(tans==N-1)
        {
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/gongdakai/p/11265861.html