WA 3个点
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n;
int ind[N];
vector<int> e[N];
int ans;
void topo()
{
queue<int> q;
for (int i = 1; i <= n; i++)
if (!ind[i])
q.push(i);
while (q.size())
{
int u = q.front();
q.pop();
ans++;
for (auto v : e[u])
{
if (--ind[v] == 0)
q.push(v);
}
}
return;
}
int main()
{
cin >> n;
for (int i = 1, x, m, y; i <= n; i++)
{
cin >> x >> m;
a[x] = 1;
while (m--)
{
cin >> y;
e[y].push_back(i);
ind[y]++;
}
}
topo();
if (ans != n)
cout << n - ans;
else
cout << "YES";
system("pause");
return 0;
}