Submission #730912

# Submission time Handle Problem Language Result Execution time Memory
730912 2023-04-26T15:35:51 Z MilosMilutinovic Magic Tree (CEOI19_magictree) C++14
0 / 100
2000 ms 662980 KB
/**
 *    author:  wxhtzdy
 *    created: 26.04.2023 14:44:59
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    --p;
    g[p].push_back(i);
    g[i].push_back(p);
  }
  vector<int> a(n, -1), b(n);
  for (int i = 0; i < m; i++) {
    int v, d, w;
    cin >> v >> d >> w;
    --v; --d;
    a[v] = d;
    b[v] = w;    
  }
  vector<int> rt(n);
  vector<vector<pair<int, int>>> vals(n);
  function<void(int, int)> Dfs = [&](int v, int pv) {
    int f = -1;
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      Dfs(u, v);
      if (f == -1 || vals[rt[f]].size() < vals[rt[u]].size()) {
        f = u;  
      }
    }
    rt[v] = v;
    for (int u : g[v]) {
      if (u == pv) {
        continue;
      }
      for (auto& p : vals[rt[u]]) {
        vals[rt[v]].push_back(p);
      }
    }
    sort(vals[rt[v]].begin(), vals[rt[v]].end());
    if (a[v] != -1) {
      for (auto& p : vals[rt[v]]) {     
        if (p.first > a[v]) {
          long long s = 0;
          for (auto& q : vals[rt[v]]) {
            if (q.first >= p.first && q.second > 0) {
              s += q.second;
            }
          }
          vals[rt[v]].emplace_back(p.first, -min(s, 1LL * b[v]));
          break;
        }
      }
      vals[rt[v]].emplace_back(a[v], b[v]);
    }
  };
  Dfs(0, 0);
  sort(vals[rt[0]].begin(), vals[rt[0]].end());
  long long ans = 0;
  long long sum = 0;
  for (auto& p : vals[rt[0]]) {
    sum += p.second;
    ans = max(ans, sum);
  }
  cout << ans << '\n';                 
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 13756 KB Output is correct
2 Execution timed out 2112 ms 662980 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5708 KB Output is correct
2 Incorrect 23 ms 5516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 24128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2388 KB Output is correct
2 Correct 43 ms 10108 KB Output is correct
3 Correct 36 ms 10168 KB Output is correct
4 Correct 59 ms 10228 KB Output is correct
5 Correct 16 ms 9932 KB Output is correct
6 Incorrect 321 ms 137352 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -