[Title link]
http://poj.org/problem?id=3660
title meaning
There is a group of cattle with grades from 1 to n. Now tell you the result of m games AB (A is greater than B), and ask you to determine the number of cattle of a certain grade.
Problem solving ideas
If a cow can determine its relationship with other n-1 cows, it can determine its own rank. (As long as the number of wins and losses is determined, when the number of wins plus the negative number is equal to n-1, then the level of the cow must be the negative number plus 1). So use Freud to find the pairwise relationship. In judging how much can only determine the level.
code section
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3
const int N = 105;
int n,m;
int maps[N][N];
int main()
{
while (~scanf("%d %d",&n,&m))
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
maps[i][j] = inf;
}
}
for (int i = 1; i <= m; i++)
{
int u,v;
scanf("%d %d",&u,&v);
maps[u][v] = 1; ///u大于v
maps[v][u] = -1; /// v小于u
}
for (int j = 1; j <= n; j++) ///利用点j缩点
for (int i = 1; i <= n; i++)
for (int k = 1; k <= n; k++) ///对战关系嫁接
{
if (maps[i][j] == maps[j][k] && maps[i][j] !=inf)
maps[i][k] = maps[i][j];
}
int ans = 0;
for (int i = 1; i <= n ; i++)
{
bool fa = true;
for (int j = 1; j <= n; j++)
{
if (i == j)
continue;
if (maps[i][j] == inf)
{
fa = false;
break;
}
}
if (fa)
ans++;
}
printf("%d\n",ans);
}
return 0;
}