Submission #950438

#TimeUsernameProblemLanguageResultExecution timeMemory
950438UnforgettableplFireworks (APIO16_fireworks)C++17
19 / 100
14 ms1188 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int DP[301][301]; vector<pair<int,int>> adj[301]; int n,m; void dfs(int x,int p){ if(x>n){ iota(DP[x],DP[x]+301,0); return; } for(auto&i:adj[x])if(i.first!=p) { dfs(i.first, x); for(int j=0;j<=300;j++){ int best = INT64_MAX; for(int y=0;y<=j;y++)best=min(best,DP[i.first][y]+abs(i.second+y-j)); DP[x][j]+=best; } } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i=2;i<=n+m;i++){ int a,b;cin>>a>>b; adj[a].emplace_back(i,b); adj[i].emplace_back(a,b); } dfs(1,0); cout << *min_element(DP[1],DP[1]+301) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...