5106 | 2023-04-17 17:47:50 | rmlan | Különböző katicák | cpp14 | Wrong answer 10/100 | 83ms | 46192 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;
}
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 << " ";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1876 KiB | ||||
2 | Accepted | 3ms | 1912 KiB | ||||
3 | Wrong answer | 71ms | 15628 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Accepted | 61ms | 15100 KiB | ||||
5 | Accepted | 68ms | 17232 KiB | ||||
6 | Accepted | 74ms | 19128 KiB | ||||
7 | Accepted | 82ms | 21136 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Accepted | 74ms | 41300 KiB | ||||
9 | Accepted | 75ms | 42056 KiB | ||||
10 | Wrong answer | 76ms | 44284 KiB | ||||
11 | Wrong answer | 82ms | 44512 KiB | ||||
12 | Wrong answer | 74ms | 44608 KiB | ||||
13 | Wrong answer | 75ms | 46192 KiB | ||||
14 | Accepted | 79ms | 45608 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Accepted | 3ms | 14076 KiB | ||||
16 | Wrong answer | 3ms | 14128 KiB | ||||
17 | Wrong answer | 3ms | 14388 KiB | ||||
18 | Wrong answer | 3ms | 14364 KiB | ||||
19 | Wrong answer | 3ms | 14352 KiB | ||||
20 | Wrong answer | 3ms | 14304 KiB | ||||
21 | Wrong answer | 3ms | 14568 KiB | ||||
22 | Wrong answer | 3ms | 14548 KiB | ||||
subtask5 | 0/40 | ||||||
23 | Accepted | 74ms | 28420 KiB | ||||
24 | Accepted | 68ms | 29784 KiB | ||||
25 | Accepted | 70ms | 31216 KiB | ||||
26 | Wrong answer | 75ms | 31212 KiB | ||||
27 | Wrong answer | 74ms | 31696 KiB | ||||
28 | Wrong answer | 82ms | 33328 KiB | ||||
29 | Wrong answer | 79ms | 34336 KiB | ||||
30 | Wrong answer | 78ms | 34720 KiB | ||||
31 | Wrong answer | 67ms | 35344 KiB | ||||
32 | Wrong answer | 81ms | 36576 KiB | ||||
33 | Wrong answer | 83ms | 38100 KiB |