Submission #1113030

#TimeUsernameProblemLanguageResultExecution timeMemory
1113030guagua0407Fireworks (APIO16_fireworks)C++17
7 / 100
12 ms14580 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=6e5+5; vector<pair<int,int>> adj[mxn]; ll d[mxn]; ll val[mxn]; pair<ll,ll> pt[mxn]; int n,m; void dfs(int v,int p=0){ if(v>n){ return; } vector<ll> vec; for(auto u:adj[v]){ dfs(u.f,v); vec.push_back(pt[u.f].f+u.s); vec.push_back(pt[u.f].s+u.s); } sort(all(vec)); int sz=(int)vec.size(); ll x=vec[sz/2]; for(auto u:adj[v]){ val[v]+=val[u.f]; if(x<(pt[u.f].f+u.s)){ val[v]+=(pt[u.f].f+u.s)-x; } else if(x>(pt[u.f].s+u.s)){ val[v]+=x-(pt[u.f].s+u.s); } } pt[v]={vec[sz/2-1],vec[sz/2]}; } signed main() {_ cin>>n>>m; for(int i=2;i<=n+m;i++){ int p,c; cin>>p>>c; adj[p].push_back({i,c}); } dfs(1); cout<<val[1]<<'\n'; return 0; } //maybe its multiset not set //yeeorz //diaoborz

Compilation message (stderr)

fireworks.cpp: In function 'void setIO(std::string)':
fireworks.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...