7642022-01-09 18:31:37Szin AttilaTitkos sorozatcpp14Wrong answer 0/4045ms33832 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;

vector<vector<int> > g(maxN);
vector<bool> volt(maxN), elhagy(maxN);
vector<int> sorrend;

void dfs(int x)
{
	volt[x] = true;
	for (int sz : g[x]) {
		if (!volt[sz]) {
			dfs(sz);
		}
		else if (!elhagy[sz]) {
			cout << "IMPOSSIBLE" << endl;
			exit(0);
		}
	}
	sorrend.push_back(x);
	elhagy[x] = true;
}

int main() {

#pragma region
#ifndef ONLINE_JUDGE
   freopen("../input.txt", "r", stdin);
   freopen("../output.txt", "w", stdout);
#endif

   InTheNameOfGod;
#pragma endregion
    
    int n;
    cin >> n;
    vector<int> v(n), mo(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int curr = n;

    for(int i = 0; i < n; i++) {
        if(v[i] == -1) mo[i] = curr--;
        else {
            g[i+1].push_back(v[i]);
        }
    }

    for (int i = 1; i <= n; i++) {
		if (!volt[i])
			dfs(i);
	}

    for(int i = 0; i < sorrend.size(); i++) {
        mo[sorrend[i]] = i+1;
    }

    for(int a : mo) cout << a << ' ';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Wrong answer0/07ms11000 KiB
2Wrong answer0/020ms16592 KiB
3Wrong answer0/16ms11380 KiB
4Wrong answer0/17ms11384 KiB
5Wrong answer0/26ms11396 KiB
6Wrong answer0/16ms11392 KiB
7Wrong answer0/16ms11400 KiB
8Wrong answer0/26ms11400 KiB
9Wrong answer0/237ms21192 KiB
10Wrong answer0/237ms21676 KiB
11Wrong answer0/235ms22376 KiB
12Wrong answer0/235ms23180 KiB
13Wrong answer0/234ms23988 KiB
14Wrong answer0/237ms24924 KiB
15Wrong answer0/235ms26228 KiB
16Wrong answer0/335ms27088 KiB
17Wrong answer0/337ms27952 KiB
18Wrong answer0/341ms28964 KiB
19Wrong answer0/341ms30380 KiB
20Wrong answer0/345ms33832 KiB
21Wrong answer0/139ms26788 KiB
22Wrong answer0/135ms27072 KiB
23Wrong answer0/132ms27300 KiB