样例没过还拿了70分,怎么会是呢(歪头),还麻烦各位大佬看看代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
int n, cnt, ans, head[N], ru[N],site[N];
struct Edge {
int next, to;
} e[N * N];
queue<int> q;
bool check(int x)
{
for(int i=1;i<=N;i++)
if(site[i]==x)
return 1;
return 0;
}
void add(int from, int to) {
e[++cnt].to = to;
e[cnt].next = head[from];
head[from] = cnt;
ru[to]++;
}
void topo() {
for (int i = 1; i <= n; i++)
if (ru[i] == 0)
q.push(i);
while (q.empty() == 0) {
ans++;
int v = q.front();
q.pop();
for (int i = head[v]; i; i = e[i].next) {
int u = e[i].to;
ru[u]--;
if (ru[i] == 0 && check(i)==1)
q.push(i);
}
}
}
int main() {
scanf("%d", &n);
int tot=1;
for (int i = 1; i <= n; i++) {
int x, m, y;
scanf("%d%d", &x, &m);
site[tot++]=x;
while (m--) {
scanf("%d", &y);
add(x, y);
}
}
topo();
if (ans == n)
cout << "YES" << endl;
else
cout << n - ans << endl;
return 0;
}