81422024-01-12 14:29:56ZsBalazsTitkos sorozatcpp17Runtime error 37/40522ms130276 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]++;
            }
        }
    }
    
    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
base37/40
1Accepted0/03ms1812 KiB
2Accepted0/046ms10216 KiB
3Accepted1/13ms2516 KiB
4Accepted1/13ms2744 KiB
5Accepted2/23ms2956 KiB
6Accepted1/14ms3252 KiB
7Accepted1/13ms3464 KiB
8Accepted2/24ms3956 KiB
9Accepted2/2119ms28296 KiB
10Accepted2/2522ms123256 KiB
11Accepted2/2104ms24088 KiB
12Accepted2/297ms23036 KiB
13Accepted2/297ms23016 KiB
14Accepted2/293ms23060 KiB
15Accepted2/292ms23004 KiB
16Accepted3/389ms23584 KiB
17Accepted3/387ms24208 KiB
18Accepted3/386ms24688 KiB
19Accepted3/383ms25236 KiB
20Accepted3/375ms25656 KiB
21Runtime error0/1282ms130276 KiB
22Runtime error0/1344ms130248 KiB
23Runtime error0/1338ms130008 KiB