Submission #990335

# Submission time Handle Problem Language Result Execution time Memory
990335 2024-05-30T08:36:34 Z imarn Magic Tree (CEOI19_magictree) C++14
0 / 100
34 ms 21844 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int mxn=1e5+5;
int d[mxn]{0},w[mxn];
map<int,int>dp[mxn];
vector<int>g[mxn];
void dfs(int u){
    for(auto v:g[u]){
        dfs(v);
        if(dp[v].size()>dp[u].size())swap(dp[u],dp[v]);
        for(auto it:dp[v]){
            dp[u][it.f]+=it.s;
        }
    }
    if(!d[u])return;
    dp[u][d[u]]+=w[u];int cur=w[u];
    auto it = dp[u].upper_bound(d[u]);
    while(it!=dp[u].end()){
        if(cur>=it->s){
            cur-=it->s;
            dp[u].erase(it->f);
        }
        else {
            dp[u][it->f]-=cur;
        }it++;
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m,k;cin>>n>>m>>k;
    for(int i=2;i<=n;i++){
        int p;cin>>p;g[p].pb(i);
    }
    for(int i=1;i<=m;i++){
        int v;cin>>v;cin>>d[v]>>w[v];
    }dfs(1);ll ans=0;
    for(auto it : dp[1])ans+=it.s;cout<<ans;
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:43:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   43 |     for(auto it : dp[1])ans+=it.s;cout<<ans;
      |     ^~~
magictree.cpp:43:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |     for(auto it : dp[1])ans+=it.s;cout<<ans;
      |                                   ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 14684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 16476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 15196 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 21844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 14684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 15964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 14684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 14684 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -