80472024-01-12 11:27:09UnluckYTitkos sorozatcpp17Time limit exceeded 0/40899ms130448 KiB
#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;


}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/03ms1848 KiB
2Time limit exceeded0/0899ms5124 KiB
3Wrong answer0/13ms2508 KiB
4Wrong answer0/13ms2728 KiB
5Wrong answer0/23ms2944 KiB
6Wrong answer0/14ms3384 KiB
7Wrong answer0/14ms3320 KiB
8Wrong answer0/24ms3564 KiB
9Time limit exceeded0/2866ms9056 KiB
10Time limit exceeded0/2865ms12464 KiB
11Time limit exceeded0/2870ms9228 KiB
12Time limit exceeded0/2870ms9484 KiB
13Time limit exceeded0/2859ms9700 KiB
14Time limit exceeded0/2874ms9968 KiB
15Time limit exceeded0/2882ms10072 KiB
16Time limit exceeded0/3853ms10592 KiB
17Time limit exceeded0/3866ms10704 KiB
18Time limit exceeded0/3865ms10980 KiB
19Time limit exceeded0/3882ms11304 KiB
20Time limit exceeded0/3874ms11480 KiB
21Runtime error0/1354ms130448 KiB
22Runtime error0/1305ms130372 KiB
23Runtime error0/1270ms130376 KiB