Submission #1020674

#TimeUsernameProblemLanguageResultExecution timeMemory
1020674pccFireworks (APIO16_fireworks)C++17
19 / 100
40 ms1884 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second #define ll long long const ll inf = 1e9; const int mxn = 330; int N,M; vector<pii> tree[mxn]; ll dp[mxn][mxn],dep[mxn]; pii par[mxn]; bitset<mxn> boom; void dfs(int now){ fill(dp[now],dp[now]+mxn,inf); if(boom[now])dp[now][dep[now]] = 0; else fill(dp[now],dp[now]+mxn,0); for(auto [nxt,w]:tree[now]){ //cerr<<now<<":"<<nxt<<endl; dep[nxt] = dep[now]+w; dfs(nxt); for(int i = 0;i<mxn;i++){ dp[now][i] += dp[nxt][i]; } } ll tmp[mxn]; fill(tmp,tmp+mxn,inf); for(int i = 0;i<mxn;i++){ for(int j = 0;j<mxn;j++){ if(i-j>=-par[now].sc)tmp[i] = min(tmp[i],dp[now][j]+abs(i-j)); } } //cerr<<now<<' '<<par[now].sc<<":";for(int j = 0;j<=30;j++)cerr<<(tmp[j]>=inf?-1:tmp[j])<<' ';cerr<<endl; for(int i = 0;i<mxn;i++)dp[now][i] = tmp[i]; return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>M; for(int i = 2;i<=N+M;i++){ int p,c; cin>>p>>c; par[i] = pii(p,c); tree[p].push_back(pii(i,c)); } for(int i = N+1;i<=N+M;i++)boom[i] = true; dfs(1); cout<<*min_element(dp[1],dp[1]+mxn)<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...