#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010, M = 10010;
int h[N], e[M], ne[M], idx;
void add(int a, int b){
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
int n, m;
bool dist[N][N];
bool st[N];
void dfs(int u, int k){
for (int i = h[k]; ~i; i = ne[i]){
int j = e[i];
if (st[j]) continue;
st[j] = true;
dist[u][j] = true;
dfs(u, j);
}
}
int main(){
scanf("%d%d", &n, &m);
memset(h, -1, sizeof h);
while(m --){
int a, b;
scanf("%d%d", &a, &b);
add(a, b);
}
for (int i = 1; i <= n; i ++){
memset(st, 0, sizeof st);
dist[i][i] = true;
dfs(i, i);
}
int ans = 0;
for (int i = 1; i <= n; i ++){
int j;
for (j = 1; j <= n; j ++){
if (!dist[i][j] && !dist[j][i]) break;
}
if (j > n) ans ++;
}
cout << ans << endl;
return 0;
}
通信网络-------201709-4
最新推荐文章于 2023-03-15 15:48:04 发布