81482024-01-12 14:39:18ZsBalazsTitkos sorozatcpp17Runtime error 0/40347ms129744 KiB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> graph;
vector<int> megoldas;
vector<int> mutat;
vector<bool> volt;

void bejar(int current) {
    if (volt[current]) return;
    
    volt[current] = true;
    
    for (int szom : graph[current]) {
        if (megoldas[szom] < megoldas[current]+1) {
            megoldas[szom] = megoldas[current]+1;
        }
        mutat[szom]--;
    }
}

int main() {
    int n;
    cin >> n;
    
    graph.resize(n);
    megoldas.assign(n, 0);
    mutat.assign(n, 0);
    volt.assign(n, false);
    
    for (int i = 0; n > i; i++) {
        int temp;
        cin >> temp;
        
        if (temp != -1) {
            temp--;
            
            mutat[temp]++;
            graph[i].push_back(temp);
            
            for (int j = i+1; temp > j; j++) {
                mutat[i]++;
                graph[j].push_back(i);
            }
        } else {
            for (int j = i+1; n > j; j++) {
                graph[j].push_back(i);
                mutat[i]++;
            }
        }
    }
    
    return 1;
    
    int counter = 0;
    while (counter < n) {
        for (int i = 0; n > i; i++) {
            if (mutat[i] == 0 && !volt[i]) {
                bejar(i);
                counter++;
            }
        }   
    }
    
    // megoldas, index
    vector<pair<int, int>> sor;
    
    for (int i = 0; n > i; i++) {
        sor.push_back({megoldas[i], i});
    }
    
    sort(sor.begin(), sor.end());
    
    vector<int> ans(n, 0);
    
    int next = 1;
    for (int i = 0; n > i; i++) {
        int index = sor[i].second;
        
        ans[index] = next;
        
        next++;
    }
    
    for (int a : ans) {
        cout << a << " ";
    }
    cout << endl;
    
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Runtime error0/03ms1872 KiB
2Runtime error0/028ms9204 KiB
3Runtime error0/13ms2908 KiB
4Runtime error0/13ms2960 KiB
5Runtime error0/23ms2780 KiB
6Runtime error0/13ms3224 KiB
7Runtime error0/13ms3444 KiB
8Runtime error0/24ms3944 KiB
9Runtime error0/271ms25664 KiB
10Runtime error0/2239ms121052 KiB
11Runtime error0/264ms21844 KiB
12Runtime error0/259ms20944 KiB
13Runtime error0/257ms20944 KiB
14Runtime error0/257ms20996 KiB
15Runtime error0/254ms21192 KiB
16Runtime error0/354ms21428 KiB
17Runtime error0/354ms22116 KiB
18Runtime error0/352ms22744 KiB
19Runtime error0/352ms23136 KiB
20Runtime error0/348ms23852 KiB
21Runtime error0/1342ms129744 KiB
22Runtime error0/1280ms129652 KiB
23Runtime error0/1347ms129632 KiB