版本比较
拓扑排序
正文
增加 10 行删除 10 行
27 行未改动2829303132323334353536373839394041424243444445464748495050515253535455565657585959606162636364656627 行未改动stack <int> sta;//也可以用queue
int main(void) { cin >> n;
for (int i = 1; i <= n; i ++) { int A;
while(1) { cin >> A; if(!A) break;
a[i][++ out[i]] = A; in[A] ++; } } }
for (int i = 1; i <= n; i ++) { if(!in[i]) { sta.push(i); } }
while (sta.size()) { int t = sta.top();
cout << t << ' '; sta.pop();
for (int i = 1; i <= out[t]; i ++) { in[a[t][i]] --;
if(!in[a[t][i]]) sta.push(a[t][i]); } }
return 0;}```