51072023-04-17 17:51:23rmlanKülönböző katicákcpp14Wrong answer 10/10090ms39500 KiB
#include<bits/stdc++.h>
using namespace std;

int n;
bool jo=1;
vector<int> p,m;
vector<pair<int, int> > l,e;
vector<vector<int>> g;

void dfs1(int u){
    for(int v:g[u]){
        dfs1(v);
        e.push_back({v,u});
        if(l[u].first == 0 && l[u].second == 1e6) continue;

        l[v].first = max(max(l[v].first, l[u].first-1),0);
        l[v].second = min(l[v].second, l[u].second+1);
        if(l[v].first%2 == l[u].first%2 || l[v].first > l[v].second) jo=0;
    }
}

int main(){
    pair<int, int> df = {0,1e6};
    cin >> n;
    p.resize(n+1);
    l.resize(n+1);
    g.resize(n+1);
    m.resize(n+1);


    for(int i = 1; i <= n; i++){
        l[i] = {0, 1e6};
        cin>>p[i];
        g[p[i]].push_back(i);

    }
    for(int i = 1; i <= n; i++){
        cin >> m[i];
        if(m[i] != -1) l[i]={m[i], m[i]};
    }
    dfs1(1);
    reverse(e.begin(), e.end());
    for(pair<int, int> pa:e){
        int fi=pa.first,se=pa.second;
        if(l[se]!=df && l[fi]!=df &&l[se].first%2 == l[fi].first%2) jo=0;
        l[se].first=max(max(l[se].first, l[fi].first-1),0);
        l[se].second=min(l[se].second, l[fi].second+1);
        if(l[se].first > l[se].second) jo = 0;
    }
    dfs1(1);
    if(!jo){
        cout << "NEM";
        return 0;
    }
    cout << "IGEN\n";

    for(int i = 1; i <= n; i++){
        if(l[1] == df){
            cout << m[p[i]]+1 << " ";
            m[i] = m[p[i]]+1;
            continue;
        }
        cout << l[i].second << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1876 KiB
2Accepted3ms2120 KiB
3Wrong answer68ms16900 KiB
subtask210/10
4Accepted67ms15888 KiB
5Accepted72ms17036 KiB
6Accepted78ms18060 KiB
7Accepted86ms19376 KiB
subtask30/15
8Accepted82ms38824 KiB
9Accepted76ms38660 KiB
10Wrong answer86ms39500 KiB
11Wrong answer89ms38820 KiB
12Wrong answer79ms38232 KiB
13Wrong answer79ms39008 KiB
14Accepted86ms37544 KiB
subtask40/35
15Accepted3ms3776 KiB
16Accepted3ms3784 KiB
17Wrong answer3ms3804 KiB
18Wrong answer3ms3900 KiB
19Wrong answer3ms4072 KiB
20Wrong answer3ms4032 KiB
21Wrong answer3ms4028 KiB
22Wrong answer3ms4456 KiB
subtask50/40
23Accepted78ms19224 KiB
24Accepted74ms19780 KiB
25Accepted75ms20132 KiB
26Wrong answer81ms19276 KiB
27Wrong answer79ms19176 KiB
28Wrong answer85ms19996 KiB
29Wrong answer71ms20060 KiB
30Wrong answer68ms19760 KiB
31Wrong answer71ms19476 KiB
32Wrong answer83ms19500 KiB
33Wrong answer90ms20344 KiB