제출 #967980

#제출 시각아이디문제언어결과실행 시간메모리
967980TAhmed33Fireworks (APIO16_fireworks)C++98
0 / 100
3 ms7516 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MAXN = 3e5 + 25; vector <pair <int, int>> adj[MAXN]; int dp[MAXN], n, m; void dfs (int pos) { for (auto j : adj[pos]) { dfs(j.first); } dp[pos] = 1e18; for (int i = 0; i <= 300; i++) { int sum = 0; for (auto j : adj[pos]) { sum += abs(i - j.second) + dp[j.first]; } dp[pos] = min(dp[pos], sum); } } signed main () { cin >> n >> m; n += m; for (int i = 2; i <= n; i++) { int x, y; cin >> x >> y; adj[x].push_back({i, y}); } dfs(1); cout << dp[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...