#include<bits/stdc++.h>
using namespace std;
vector<int> nbr[205];
int n, in[10005], cnt, w[105];
bool vis[505];
void topo()
{
queue<int> q;
for (int i = 1 ; i <= n ; i++)
{
if (in[w[i]] == 0)
{
q.push(w[i]);
}
}
while (q.empty() == false)
{
int cur = q.front();
q.pop();
for (int i = 0 ; i < nbr[cur].size() ; i++)
{
int nxt = nbr[cur][i];
in[nxt]--;
if(in[nxt] == 0 && vis[nxt] == true)
{
q.push(nxt);
vis[nxt] = false;
}
}
}
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1 ; i <= n ; i++)
{
int m;
cin >> w[i] >> m;
vis[w[i]] = true;
for (int j = 1 ; j <= m ; j++)
{
int opt;
cin >> opt;
nbr[w[i]].push_back(opt);
in[opt]++;
}
}
topo();
for (int i = 1 ; i <= n ; i++)
{
if(in[w[i]] == 0)
{
cnt++;
}
}
if (cnt == 0)
{
cout << "YES";
}
else
{
cout << cnt;
}
return 0;
}
样例是 2,输出 3。cnt 统计摄像头数量,visi 表示一个摄像机有没有被砸。