Submission #990338

# Submission time Handle Problem Language Result Execution time Memory
990338 2024-05-30T08:43:15 Z imarn Magic Tree (CEOI19_magictree) C++14
0 / 100
39 ms 17720 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};ll w[mxn];
map<int,ll>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]){
            if(dp[u].find(it.f)!=dp[u].end())dp[u][it.f]+=it.s;
            else dp[u][it.f]=it.s;
        }
    }
    if(d[u]==0)return;
    if(dp[u].find(d[u])==dp[u].end())dp[u][d[u]]=w[u];
    else dp[u][d[u]]+=w[u];
    ll cur=w[u];
    auto it = dp[u].upper_bound(d[u]);
    for(;it!=dp[u].end();it++){
        cout<<it->f<<' ';
        if(cur>=it->s){
            cur-=it->s;
        }
        else {
            //dp[u][it->f]-=cur;
            break;
        }
    }
}
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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 17720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 14124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -