# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1109728 | Trisanu_Das | 트리 (IOI24_tree) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_NODES = 300005;
int n,, child_count[MAX_NODES], leaf_count;
vector<int> parent, weight;
void initialize(const vector<int>& _parent, const vector<int>& _weight) {
parent = _parent;
weight = _weight;
n = parent.size();
fill(child_count, child_count + n, 0);
leaf_count = 0;
for (int i = 1; i < n; i++) child_count[parent[i]]++;
for (int i = 0; i < n; i++) if (child_count[i] == 0) leaf_count++;
}
ll query(int left, int right) {
return leaf_count * (ll)left + max(0LL, leaf_count * (ll)left - right);
}