Submission #836711

#TimeUsernameProblemLanguageResultExecution timeMemory
836711JuanMagic Tree (CEOI19_magictree)C++17
0 / 100
113 ms16048 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define tii tuple<int,int,int,int> #define pii pair<int,int> #define ff first #define ss second #define all(x) x.begin(),x.end() const int maxn = 1e5 + 5; vector<int> g[maxn]; int tin[maxn], tout[maxn], pai[maxn], ans_arr[maxn], depth[maxn]; vector<tii> fruits; int timer=1; void elr_tr(int u, int p){ tin[u] = timer++; depth[u] = depth[p]+1; for(int v : g[u]) if(v!=p){ elr_tr(v,u); } tout[u] = timer; } int bit[maxn]; void upd(int x, int val){ for(; x < maxn; x+=x&-x) bit[x] += val; } int query(int l, int r){ int rt = 0; for(int i = r; i>0; i-=i&-i) rt += bit[i]; for(int i = l-1; i>0; i-=i&-i) rt -= bit[i]; return rt; } int solve(int u, int p){ int aux = 0; for(int v : g[u]) if(v!=p){ aux += solve(v,u); } return max(ans_arr[u], aux); } int32_t main(){ int n, m, k; cin >> n >> m >> k; for(int i = 2; i <= n; i++){ int p; cin >> p; pai[i] = p; g[i].push_back(p); g[p].push_back(i); } elr_tr(1,1); for(int i = 0; i < m; i++){ int v, d, w; cin >> v >> d >> w; fruits.push_back({d,-depth[v],v,w}); } sort(all(fruits)); for(int i = 0; i < fruits.size(); i++){ auto[d,dep,u,w] = fruits[i]; upd(tin[u], w); ans_arr[u] = query(tin[u], tout[u]); } cout << solve(1,1) << '\n'; }

Compilation message (stderr)

magictree.cpp: In function 'int32_t main()':
magictree.cpp:63:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i = 0; i < fruits.size(); 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...