7632022-01-09 18:30:18Szin AttilaTitkos sorozatcpp14Wrong answer 0/4056ms31448 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].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/08ms11016 KiB
2Wrong answer0/021ms17204 KiB
3Wrong answer0/16ms11372 KiB
4Wrong answer0/14ms11376 KiB
5Wrong answer0/24ms11424 KiB
6Wrong answer0/16ms11388 KiB
7Wrong answer0/17ms11388 KiB
8Wrong answer0/26ms11392 KiB
9Wrong answer0/237ms21980 KiB
10Wrong answer0/232ms22048 KiB
11Wrong answer0/235ms23656 KiB
12Wrong answer0/235ms24476 KiB
13Wrong answer0/232ms25308 KiB
14Wrong answer0/235ms26144 KiB
15Wrong answer0/239ms27228 KiB
16Wrong answer0/335ms27828 KiB
17Wrong answer0/334ms28580 KiB
18Wrong answer0/334ms29240 KiB
19Wrong answer0/343ms30088 KiB
20Wrong answer0/354ms31448 KiB
21Wrong answer0/150ms26864 KiB
22Wrong answer0/146ms27220 KiB
23Wrong answer0/156ms27304 KiB