51102023-04-17 18:24:48rmlanKülönböző katicákcpp14Wrong answer 0/10082ms39700 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].second%2 == l[u].second%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].second%2 == l[fi].second%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 << " ";
    }
/*for(pair<int, int> a:l){
        cout << a.first <<" " << a.second<< endl;
    }*/
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1880 KiB
2Accepted3ms2116 KiB
3Wrong answer64ms16936 KiB
subtask20/10
4Wrong answer56ms15852 KiB
5Wrong answer61ms17020 KiB
6Wrong answer65ms18044 KiB
7Wrong answer71ms19228 KiB
subtask30/15
8Accepted81ms38836 KiB
9Accepted79ms38748 KiB
10Wrong answer82ms39700 KiB
11Wrong answer79ms38832 KiB
12Wrong answer75ms38444 KiB
13Wrong answer81ms39048 KiB
14Wrong answer75ms37844 KiB
subtask40/35
15Wrong answer3ms4288 KiB
16Accepted3ms4248 KiB
17Accepted3ms4500 KiB
18Wrong answer3ms4528 KiB
19Wrong answer3ms4532 KiB
20Wrong answer3ms4536 KiB
21Wrong answer3ms4452 KiB
22Wrong answer3ms4460 KiB
subtask50/40
23Wrong answer68ms19672 KiB
24Accepted71ms20224 KiB
25Accepted72ms20592 KiB
26Wrong answer68ms19856 KiB
27Wrong answer68ms19640 KiB
28Wrong answer72ms20272 KiB
29Wrong answer71ms20340 KiB
30Wrong answer70ms20008 KiB
31Wrong answer68ms19812 KiB
32Wrong answer71ms20096 KiB
33Wrong answer75ms20576 KiB