8046 | 2024-01-12 11:26:50 | UnluckY | Titkos sorozat | csharp | Forditási hiba |
#include <bits/stdc++.h>
using namespace std;
vector<int> tops;
vector<bool> seen;
vector<vector<int>> v;
void dfs(int x){
if (seen[x]) return;
seen[x] = true;
for (int i : v[x]) dfs(i);
tops.push_back(x);
}
int main() {
int n; cin >> n;
v.assign(n+1, {});
seen.assign(n+1, false);
vector<pair<int, int>> vv;
for (int i = 1; i <= n; i++){
int a; cin >> a;
if (a == -1){
vv.push_back({i, n+1});
continue;
}
v[i].push_back(a);
vv.push_back({i, a});
for (pair<int, int> j : vv){
if (j.second >= a) v[a].push_back(j.first);
}
}
for (int i = 1; i <= n; i++) dfs(i);
reverse(tops.begin(), tops.end());
for (int i : tops) cout << i << " ";
return 0;
}
exit status 1
Compilation failed: 6 error(s), 0 warnings