7792 | 2024-01-11 10:17:31 | gortomi | Különböző katicák | cpp17 | Wrong answer 65/100 | 52ms | 40888 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<int> l, r, p, val, a;
void dfs(int v)
{
for(auto x : g[v])
{
dfs(x);
if(p[x] != -1) p[v] = 1 - p[x];
l[v] = max(l[v], l[x] - 1);
r[v] = min(r[v], r[x] + 1);
}
if(p[v] == -1 && a[v] != -1) p[v] = a[v] % 2;
if(a[v] != -1 && p[v] != (a[v] % 2))
{
cout << "NEM\n";
exit(0);
}
}
void calc(int v)
{
for(auto x : g[v])
{
if(val[v] - 1 < l[x]) val[x] = val[v] + 1;
else val[x] = val[v] - 1;
calc(x);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
g.resize(n + 1);
l.resize(n + 1, 0);
r.resize(n + 1, 1e7);
a.resize(n + 1);
p.resize(n + 1, -1);
val.resize(n + 1);
for(int i = 1; i <= n; i++)
{
int x;
cin >> x;
g[x].push_back(i);
}
for(int i = 1; i <= n; i++)
{
cin >> a[i];
if(a[i] != -1) l[i] = r[i] = a[i];
}
dfs(1);
for(int i = 1; i <= n; i++)
{
if(l[i] > r[i])
{
cout << "NEM\n";
return 0;
}
}
val[1] = l[1];
calc(1);
cout << "IGEN\n";
for(int i = 1; i <= n; i++) cout << val[i] << " ";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1892 KiB | ||||
2 | Accepted | 3ms | 2120 KiB | ||||
3 | Accepted | 41ms | 14248 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Accepted | 35ms | 13688 KiB | ||||
5 | Accepted | 39ms | 15688 KiB | ||||
6 | Accepted | 43ms | 17228 KiB | ||||
7 | Accepted | 46ms | 19152 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 39ms | 36548 KiB | ||||
9 | Accepted | 39ms | 37184 KiB | ||||
10 | Accepted | 52ms | 39064 KiB | ||||
11 | Accepted | 50ms | 39012 KiB | ||||
12 | Accepted | 48ms | 39204 KiB | ||||
13 | Accepted | 50ms | 40888 KiB | ||||
14 | Accepted | 46ms | 40488 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Accepted | 3ms | 13016 KiB | ||||
16 | Wrong answer | 3ms | 12972 KiB | ||||
17 | Accepted | 3ms | 13128 KiB | ||||
18 | Accepted | 3ms | 13084 KiB | ||||
19 | Accepted | 3ms | 13352 KiB | ||||
20 | Accepted | 3ms | 13308 KiB | ||||
21 | Accepted | 3ms | 13316 KiB | ||||
22 | Accepted | 3ms | 13576 KiB | ||||
subtask5 | 40/40 | ||||||
23 | Accepted | 43ms | 25996 KiB | ||||
24 | Accepted | 34ms | 27716 KiB | ||||
25 | Accepted | 35ms | 28928 KiB | ||||
26 | Accepted | 43ms | 29016 KiB | ||||
27 | Accepted | 45ms | 29688 KiB | ||||
28 | Accepted | 46ms | 31440 KiB | ||||
29 | Accepted | 48ms | 32580 KiB | ||||
30 | Accepted | 45ms | 32904 KiB | ||||
31 | Accepted | 43ms | 33652 KiB | ||||
32 | Accepted | 45ms | 34528 KiB | ||||
33 | Accepted | 48ms | 36160 KiB |