4996 | 2023-04-08 16:41:58 | TomaSajt | Különböző katicák | cpp17 | Hibás válasz 10/100 | 87ms | 35888 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> subordinates;
vector<int> boss, spots, parity, range_start, range_end;
bool impossible = false;
void range_dfs(int u) {
for (int v : subordinates[u]) {
range_dfs(v);
range_start[u] = max(range_start[u], range_start[v] - 1);
range_end[u] = max(range_end[u], range_end[v] + 1);
if (parity[u] == -1 && parity[v] != -1)
parity[u] = !parity[v];
if (parity[u] != -1 && parity[u] == parity[v])
impossible = true;
}
if (range_start[u] > range_end[u])
impossible = true;
}
void fill_dfs(int u) {
if (spots[u] == -1) {
int bs = spots[boss[u]];
spots[u] = bs + 1 <= range_end[u] ? bs + 1 : bs - 1;
}
for (int v : subordinates[u])
fill_dfs(v);
}
int main() {
int n;
cin >> n;
subordinates.resize(n + 1);
boss.resize(n + 1);
spots.resize(n + 1);
parity.resize(n + 1, -1);
range_start.resize(n + 1, INT_MIN / 2);
range_end.resize(n + 1, INT_MAX / 2);
for (int i = 1; i <= n; i++) {
cin >> boss[i];
subordinates[boss[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> spots[i];
if (spots[i] != -1) {
parity[i] = spots[i] % 2;
range_start[i] = range_end[i] = spots[i];
}
}
range_dfs(1);
if (impossible) {
cout << "NEM";
return 0;
}
fill_dfs(1);
cout << "IGEN\n";
for (int i = 1; i <= n; i++)
cout << spots[i] << ' ';
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 3ms | 1872 KiB | ||||
2 | Elfogadva | 3ms | 2068 KiB | ||||
3 | Elfogadva | 74ms | 13240 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Elfogadva | 64ms | 12216 KiB | ||||
5 | Elfogadva | 70ms | 13468 KiB | ||||
6 | Elfogadva | 75ms | 14440 KiB | ||||
7 | Elfogadva | 82ms | 15696 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Elfogadva | 74ms | 34992 KiB | ||||
9 | Hibás válasz | 83ms | 34892 KiB | ||||
10 | Elfogadva | 87ms | 35888 KiB | ||||
11 | Elfogadva | 86ms | 35328 KiB | ||||
12 | Elfogadva | 85ms | 34628 KiB | ||||
13 | Elfogadva | 86ms | 35636 KiB | ||||
14 | Elfogadva | 79ms | 34324 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Elfogadva | 3ms | 4268 KiB | ||||
16 | Elfogadva | 3ms | 4224 KiB | ||||
17 | Hibás válasz | 3ms | 4476 KiB | ||||
18 | Elfogadva | 3ms | 4432 KiB | ||||
19 | Elfogadva | 3ms | 4432 KiB | ||||
20 | Elfogadva | 3ms | 4428 KiB | ||||
21 | Elfogadva | 3ms | 4428 KiB | ||||
22 | Elfogadva | 3ms | 4444 KiB | ||||
subtask5 | 0/40 | ||||||
23 | Elfogadva | 75ms | 15736 KiB | ||||
24 | Elfogadva | 67ms | 16256 KiB | ||||
25 | Hibás válasz | 85ms | 16776 KiB | ||||
26 | Elfogadva | 75ms | 15736 KiB | ||||
27 | Elfogadva | 75ms | 15992 KiB | ||||
28 | Elfogadva | 83ms | 16880 KiB | ||||
29 | Elfogadva | 82ms | 16932 KiB | ||||
30 | Elfogadva | 79ms | 16432 KiB | ||||
31 | Elfogadva | 76ms | 16412 KiB | ||||
32 | Elfogadva | 79ms | 16412 KiB | ||||
33 | Elfogadva | 86ms | 17068 KiB |