Submission #1024191

# Submission time Handle Problem Language Result Execution time Memory
1024191 2024-07-15T15:28:16 Z vjudge1 Fireworks (APIO16_fireworks) C++17
0 / 100
4 ms 7516 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int n,m,p,c,r=0;
vector<pair<int,int>>ad[300000];

pair<long long,long long>dfs(int u){
    if(ad[u].empty())return {0,0};
    long long c1=0,c2=0;
    pair<long long,long long>op;
    vector<pair<long long,long long>>t;
    for(auto v:ad[u]){
        t.push_back(dfs(v.first));
        t.back().first+=v.second;
        t.back().second+=v.second;
    }
    sort(t.begin(),t.end());
    if(t.size()&1)op=t[t.size()/2];
    else op={t[t.size()/2-1].second,t[t.size()/2].first};
    if(op.second<op.first)swap(op.first,op.second);
    for(auto v:t){
        c1+=min(abs(op.first-v.first),abs(op.first-v.second));
        c2+=min(abs(op.second-v.first),abs(op.second-v.second));
    }
    if(c1==c2)r+=c1;
    else if(c1<c2)op.second=op.first,r+=c1;
    else op.first=op.second,r+=c2;
    return op;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif
    cin>>n>>m;
    for(int i=2;i<=n+m;i++){
        cin>>p>>c;
        ad[p].push_back({i,c});
    }
    dfs(1);
    cout<<r;
    return 1<<32;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:46:13: warning: left shift count >= width of type [-Wshift-count-overflow]
   46 |     return 1<<32;
      |            ~^~~~
fireworks.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
fireworks.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("test.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -