Submission #1020647

#TimeUsernameProblemLanguageResultExecution timeMemory
1020647pccFireworks (APIO16_fireworks)C++17
0 / 100
5 ms544 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second #define ll long long const int mxn = 330; int N,M; vector<pii> tree[mxn]; int dp[mxn][mxn],dep[mxn]; int par[mxn]; bitset<mxn> boom; void dfs(int now){ if(boom[now]){ for(int i = 0;i<mxn;i++)dp[now][i] = abs(dep[now]-i); } for(auto [nxt,w]:tree[now]){ dep[nxt] = dep[now]+w; dfs(nxt); for(int i = 0;i<mxn;i++){ int mn = 1e9; for(int j = 0;j<mxn;j++){ mn = min(mn,dp[nxt][j]+abs(i-j)); } dp[now][i] += mn; } } 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] = p; 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...