3914 | 2023-03-05 12:59:41 | zsombor | Különböző katicák | cpp17 | Wrong answer 0/100 | 90ms | 36468 KiB |
#include <iostream>
#include <vector>
using namespace std;
int n;
bool lehet = true;
vector <vector <int>> g(1e5 + 1);
vector <int> f(1e5 + 1, 0);
vector <int> p(1e5 + 1, -1);
vector <int> mn(1e5 + 1, -1e9);
vector <int> mx(1e5 + 1, 1e9);
vector <int> par(1e5 + 1, -1);
void dfs1(int x) {
if (p[x] > -1) {
mn[x] = mx[x] = p[x];
par[x] = p[x] % 2;
}
for (int i : g[x]) {
dfs1(i);
mn[x] = max(mn[x], mn[i] - 1);
mx[x] = min(mx[x], mx[i] + 1);
if (par[x] == -1 && par[i] > -1) par[x] = 1 - par[i];
if (par[x] > -1 && par[i] > -1 && par[x] == par[i]) lehet = false;
}
if (mn[x] > mx[x]) lehet = false;
}
void dfs2(int x) {
if (p[x] == -1) p[x] = (p[f[x]] - 1 >= mn[x] ? p[f[x]] - 1 : p[f[x]] + 1);
for (int i : g[x]) dfs2(i);
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> f[i];
g[f[i]].push_back(i);
}
for (int i = 1; i <= n; i++) cin >> p[i];
dfs1(1);
if (!lehet) { cout << "NEM"; return 0; }
p[1] = (par[1] == -1 ? 0 : mn[1]);
dfs2(1);
cout << "IGEN\n";
for (int i = 1; i <= n; i++) cout << p[i] << " ";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 7ms | 10180 KiB | ||||
2 | Accepted | 6ms | 10388 KiB | ||||
3 | Wrong answer | 71ms | 14356 KiB | ||||
subtask2 | 0/10 | ||||||
4 | Wrong answer | 64ms | 14032 KiB | ||||
5 | Wrong answer | 71ms | 14508 KiB | ||||
6 | Wrong answer | 75ms | 15208 KiB | ||||
7 | Wrong answer | 82ms | 15544 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Accepted | 72ms | 35636 KiB | ||||
9 | Accepted | 71ms | 35324 KiB | ||||
10 | Wrong answer | 90ms | 36468 KiB | ||||
11 | Wrong answer | 85ms | 35928 KiB | ||||
12 | Accepted | 86ms | 35072 KiB | ||||
13 | Accepted | 86ms | 35900 KiB | ||||
14 | Wrong answer | 81ms | 34620 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Wrong answer | 7ms | 12416 KiB | ||||
16 | Accepted | 7ms | 12248 KiB | ||||
17 | Accepted | 6ms | 12380 KiB | ||||
18 | Wrong answer | 7ms | 12364 KiB | ||||
19 | Accepted | 6ms | 12508 KiB | ||||
20 | Wrong answer | 7ms | 12632 KiB | ||||
21 | Wrong answer | 6ms | 12756 KiB | ||||
22 | Accepted | 6ms | 12800 KiB | ||||
subtask5 | 0/40 | ||||||
23 | Wrong answer | 74ms | 16716 KiB | ||||
24 | Accepted | 65ms | 16992 KiB | ||||
25 | Accepted | 67ms | 16984 KiB | ||||
26 | Wrong answer | 75ms | 16804 KiB | ||||
27 | Wrong answer | 75ms | 16800 KiB | ||||
28 | Accepted | 82ms | 16912 KiB | ||||
29 | Wrong answer | 79ms | 16912 KiB | ||||
30 | Wrong answer | 75ms | 16952 KiB | ||||
31 | Wrong answer | 78ms | 16716 KiB | ||||
32 | Wrong answer | 79ms | 16808 KiB | ||||
33 | Wrong answer | 82ms | 17068 KiB |