Submission #875173

# Submission time Handle Problem Language Result Execution time Memory
875173 2023-11-18T18:26:28 Z Ahmed57 Arboras (RMI20_arboras) C++17
0 / 100
5000 ms 9904 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
vector<array<long long,2>> adj[100001];
long long all = 0;long long ans[100001];
pair<long long,long long> par[100001];
long long mod = 1000000007;
void dfs(int i,int pr){
    for(auto j:adj[i]){
        if(j[0]==pr)continue;
        dfs(j[0],i);
        ans[i] = max(ans[i],ans[j[0]]);
    }
    ans[i]+=par[i].second;
    all+=ans[i];all%=mod;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    int p[n],d[n];
    for(int i = 1;i<n;i++)cin>>p[i];
    for(int i = 1;i<n;i++){
        cin>>d[i];
        adj[p[i]].push_back({i,d[i]});
        par[i] = {p[i],d[i]};
    }
    dfs(0,0);
    cout<<all<<endl;
    int q;cin>>q;
    while(q--){
        int v,e;
        cin>>v>>e;
        long long xd = ans[v]+e;
        par[v].second+=e;
        ans[v]+=e;
        all+=e;all%=mod;
        while(v!=0){
            v = par[v].first;
            xd+=par[v].second;
            all-=ans[v];all%=mod;all+=mod;all%=mod;
            ans[v] = max(ans[v],xd);
            all+=ans[v];all%=mod;
        }
        cout<<((all-ans[0])%mod+mod)%mod<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 9300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5025 ms 9904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -