Submission #1265014

#TimeUsernameProblemLanguageResultExecution timeMemory
1265014nicolo_010Tree (IOI24_tree)C++20
7 / 100
63 ms25924 KiB
#include "tree.h"
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
using ll = long long;
#define rep(i, k, n) for (int i=k; i<n; i++)

#define cerr if(0) cerr

v<int> p, w;
int N;
v<v<int>> adj;
v<int> leaf;
v<int> isleaf;

void dfs(int n, int p=-1) {
  bool can = true;
  for (auto x : adj[n]) {
    if (x == p) continue;
    can = false;
    dfs(x, n);
  }
  if (can) leaf.push_back(n);
}

void init(std::vector<int> P, std::vector<int> W) {
  p = P;
  w = W;
  N = (int)p.size();
  adj.resize(N);
  rep(i, 1, N) {
    //cerr << i << endl;
    adj[P[i]].push_back(i);
    adj[i].push_back(P[i]);
  }
  isleaf.assign(N, 0);
  dfs(0);
  for (auto x : leaf) isleaf[x]=1;
}

long long query(int L, int R) {
  ll k = leaf.size();
  return k*L+max(0ll, k*L-R);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...