10181 | 2024-03-29 10:40:53 | 111 | Különböző katicák | cpp17 | Wrong answer 0/100 | 61ms | 44620 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<vector<int>>g(N+1);
vector<int>p(N+1);
for(int i=1;i<=N;i++){
cin>>p[i];
if(i==1){
continue;
}
g[p[i]].push_back(i);
g[i].push_back(p[i]);
}
vector<int>v(N+1);
for(int i=1;i<=N;i++){
cin>>v[i];
}
vector<pair<int,int>>w(N+1);
auto dfs=[&](auto self,int i)->pair<int,int>{
pair<int,int>a={v[i],v[i]};
for(int j:g[i]){
pair<int,int>b=j==p[i]?v[j]==-1?pair<int,int>{-1,-1}:pair<int,int>{abs(v[j]-1),v[j]+1}:self(self,j);
if(b.first==-1&&b.second==-1){
continue;
}
if(a.first==-1&&a.second==-1){
a=b;
continue;
}
if(a.first%2!=b.first%2||b.first>a.second||b.second<a.first){
cout<<"NEM"<<'\n';
exit(0);
}
a.first=max(a.first,b.first);
a.second=min(a.second,b.second);
}
w[i]=a;
if(a.first!=-1&&a.second!=-1){
a.first=a.first==0?a.first+1:a.first-1;
a.second++;
}
return a;
};
dfs(dfs,1);
v[1]=w[1].first;
auto dfs2=[&](auto self,int i)->void{
for(int j:g[i]){
if(j==p[i]){
continue;
}
if(v[j]==-1){
v[j]=v[i]+1;
}
else{
if(w[j].first<=v[i]+1&&v[i]+1<=w[j].second){
v[j]=v[i]+1;
}
else{
v[j]=v[i]-1;
}
}
self(self,j);
}
};
dfs2(dfs2,1);
for(int i=1;i<=N;i++){
if(v[i]<0)exit(1);
}
cout<<"IGEN"<<'\n';
for(int i=1;i<=N;i++){
cout<<v[i]<<' ';
}
cout<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1956 KiB | ||||
2 | Accepted | 3ms | 2092 KiB | ||||
3 | Wrong answer | 46ms | 18436 KiB | ||||
subtask2 | 0/10 | ||||||
4 | Runtime error | 32ms | 16540 KiB | ||||
5 | Runtime error | 37ms | 18152 KiB | ||||
6 | Runtime error | 39ms | 19696 KiB | ||||
7 | Runtime error | 43ms | 21584 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Accepted | 46ms | 43712 KiB | ||||
9 | Accepted | 48ms | 43304 KiB | ||||
10 | Wrong answer | 61ms | 44620 KiB | ||||
11 | Wrong answer | 59ms | 43644 KiB | ||||
12 | Wrong answer | 54ms | 42828 KiB | ||||
13 | Wrong answer | 61ms | 43912 KiB | ||||
14 | Runtime error | 45ms | 42316 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Runtime error | 3ms | 4060 KiB | ||||
16 | Accepted | 3ms | 4064 KiB | ||||
17 | Accepted | 3ms | 4060 KiB | ||||
18 | Wrong answer | 3ms | 3996 KiB | ||||
19 | Wrong answer | 3ms | 4268 KiB | ||||
20 | Wrong answer | 3ms | 4128 KiB | ||||
21 | Wrong answer | 3ms | 4248 KiB | ||||
22 | Wrong answer | 3ms | 4276 KiB | ||||
subtask5 | 0/40 | ||||||
23 | Runtime error | 39ms | 20872 KiB | ||||
24 | Accepted | 37ms | 21580 KiB | ||||
25 | Accepted | 37ms | 22368 KiB | ||||
26 | Wrong answer | 48ms | 20872 KiB | ||||
27 | Wrong answer | 48ms | 20872 KiB | ||||
28 | Wrong answer | 54ms | 21892 KiB | ||||
29 | Wrong answer | 50ms | 22096 KiB | ||||
30 | Wrong answer | 50ms | 21428 KiB | ||||
31 | Wrong answer | 50ms | 21208 KiB | ||||
32 | Wrong answer | 52ms | 21272 KiB | ||||
33 | Wrong answer | 54ms | 22432 KiB |