Submission #940936

#TimeUsernameProblemLanguageResultExecution timeMemory
94093612345678Fireworks (APIO16_fireworks)C++17
19 / 100
15 ms860 KiB
#include <bits/stdc++.h> using namespace std; const int nx=305; int n, m, p, c, dp[nx][nx], ans=INT_MAX; vector<pair<int, int>> d[nx]; void dfs(int u) { if (u>n) return dp[u][0]=0, void(); for (auto [v, w]:d[u]) dfs(v); for (int i=0; i<nx; i++) { int sm=0; for (auto [v, w]:d[u]) { int vl=1e9; for (int x=0; x<=i; x++) vl=min(vl, dp[v][i-x]+abs(w-x)); sm=min(sm+vl, (int)1e9); } dp[u][i]=sm; } //for (int i=0; i<nx; i++) cout<<u<<' '<<i<<' '<<dp[u][i]<<'\n'; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m; for (int i=1; i<=n+m; i++) for (int j=0; j<nx; j++) dp[i][j]=1e9; for (int i=2; i<=n+m; i++) cin>>p>>c, d[p].push_back({i, c}); dfs(1); for (int i=0; i<nx; i++) ans=min(ans, dp[1][i]); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...