下面代码只有58分,但是如果改成注释的样子,就会AC
#include <bits/stdc++.h>
using namespace std;
int n, s;
vector<int> p[101];
int ind[101];
queue<int> q;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
while (1) {
cin >> a;
if (a == 0)
break;
p[i].push_back(a);
ind[a]++;
}
}
for (int i = 1; i <= n; i++) {
if (ind[i] == 0)
s = i;//q.push(i)
}
q.push(s);//此行删除
while (!q.empty()) {
int x = q.front();
q.pop();
cout << x << " ";
for (int i = 0; i < p[x].size(); i++) {
ind[p[x][i]]--;
if (ind[p[x][i]] == 0)
q.push(p[x][i]);
}
}
return 0;
}