| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1352946 | SpyrosAliv | Tree (IOI24_tree) | C++20 | 2095 ms | 24320 KiB |
#include "tree.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n;
vector<int> p, w;
vector<vector<int>> tree;
void init(std::vector<int> P, std::vector<int> W) {
p = P;
w = W;
n = (int)p.size();
tree.resize(n);
for (int i = 1; i < n; i++) {
tree[p[i]].push_back(i);
}
}
vector<ll> sub, c;
int l, r;
void dfs(int node) {
for (auto next: tree[node]) {
dfs(next);
sub[node] += sub[next];
}
if (sub[node] < l) {
c[node] = l - sub[node];
}
else if (sub[node] > r) {
c[node] = r - sub[node];
}
sub[node] += c[node];
}
long long query(int L, int R) {
l = L;
r = R;
sub.assign(n, 0);
c.assign(n, 0);
dfs(0);
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += w[i] * abs(c[i]);
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
