Submission #645216

#TimeUsernameProblemLanguageResultExecution timeMemory
645216TimDeeArboras (RMI20_arboras)C++17
0 / 100
15 ms3456 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i,n) for (int i=0; i<n; ++i) #define pi pair<int,int> #define ppi pair<int,pi> #define f first #define s second const int mod = 1e9+7; vector<vector<int>> adj(1e5+3); vector<int> d(1e5+3,0); ppi dfs(int u, int p) { ppi ret={0,{0,0}}; for (auto v:adj[u]) { if (v==p) continue; ppi k=dfs(v,u); ret.f+=k.f; ret.s.f=max(ret.s.f,k.s.s+d[v]); if (ret.s.f>ret.s.s) swap(ret.s.f,ret.s.s); } ret.f+=ret.s.f+ret.s.s; return ret; } void solve() { int n; cin>>n; if (n>1000) return; forn(i,n-1) { int v; cin>>v; adj[v].push_back(i+1); } forn(i,n-1) cin>>d[i+1]; cout<<dfs(0,-1).f<<'\n'; int Q; cin>>Q; forn(q,Q) { int i,x; cin>>i>>x; d[i]+=x; int ans=0; cout<<dfs(0,-1).f<<'\n'; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }

Compilation message (stderr)

arboras.cpp: In function 'void solve()':
arboras.cpp:42:7: warning: unused variable 'ans' [-Wunused-variable]
   42 |   int ans=0;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...