Submission #500981

#TimeUsernameProblemLanguageResultExecution timeMemory
500981sidonMagic Tree (CEOI19_magictree)C++17
100 / 100
108 ms35548 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long void ri(auto &I){ char J = I = 0; for(; J < 48; J=getchar_unlocked()); for(; J > 47; J=getchar_unlocked()) I = I * 10 + J - 48; } signed main(){ int N, M, K, u; ll res = 0; cin >> N >> M >> K; vector<int> g[N]; ll d[N] {}, w[N] {}; map<int, ll> dp[N]; for(int i = 1; i < N; i++) ri(u), g[u-1].push_back(i); while(M--) ri(u), ri(d[u-1]), ri(w[u-1]); for(u = N; --u >= 0; ) { int h = 0; for(int v : g[u]) if(size(dp[v]) > size(dp[h])) h = v; dp[h].swap(dp[u]); for(int v : g[u]) if(v != h) for(auto &[i, j] : dp[v]) dp[u][i] += j; dp[u][d[u]] += w[u]; auto f = dp[u].upper_bound(d[u]); while(f != end(dp[u]) && (f->second -= w[u]) < 0) w[u] = -f->second, f = dp[u].erase(f); } for(auto &[i, j] : dp[0]) res += j; cout << res; }

Compilation message (stderr)

magictree.cpp:5:9: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
    5 | void ri(auto &I){
      |         ^~~~
#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...