题目链接:
题目大意:n个点,m条有向边,每条边AB,点A>点B;
通过这些数据,输出有几个点可以确定在这n个点中的排名;
样例:
5 5
4 3
4 2
3 2
1 2
2 5
4,3,1,全大于2,2 大于 5;可以确定2是第2小的数,5是第1小的数。输出2,就是2和5已知大小;
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int num=1002;
//e来记录有向图的关系;
//a来记录点与点的关系。//注意:不能用e兼顾这一功能,如果e兼顾,就成了无向图了。
int e[num][num];
int a[num][num];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int x,y;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
e[x][y]=1;//x-->y;
a[x][y]=1;
a[y][x]=1;
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i!=j&&i!=k&&j!=k&&e[i][k]&&e[k][j])
{
e[i][j]++;
a[i][j]++;
a[j][i]++;
}
}
}
}
/* for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
printf(j==n?"%d\n":"%d ",a[i][j]);*/
int c=0;
int ans=0;
for(int i=1;i<=n;i++)
{
c=0;
for(int j=1;j<=n;j++)
{
if(a[i][j])c++;
}
if(c==n-1) ans++;
}
printf("%d\n",ans);
return 0;
}