atcoder abc245 - f题解
whyxiexieni · · 个人记录
atcoder abc245 - f题解
题意
有
思路
因为
标程
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, ind[N], c, q[N];
vector<int> g[N];
void topo(){
for(int i = 1; i <= n; i++){
if(!ind[i]){
q[++c] = i;
}
}
for(int i = 1; i <= c;){
int u = q[i];
i++;
for(int v : g[u]){
ind[v]--;
if(!ind[v]){
q[++c] = v;
}
}
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for(int i = 1, u, v; i <= m; i++){
cin >> u >> v;
g[v].push_back(u);
ind[u]++;
}
topo();
cout << n - c;
return 0;
}