Submission #1034542

#TimeUsernameProblemLanguageResultExecution timeMemory
1034542_8_8_Road Closures (APIO21_roads)C++17
24 / 100
2098 ms22104 KiB
#include "roads.h" #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = (int)1e5 +12; vector<pair<int,int>> g[maxn]; ll dp[maxn][2]; int k; void dfs(int v,int pr = -1){ ll S = 0; vector<ll> can; for(auto [to,w]:g[v]){ if(to == pr) continue; dfs(to,v); S += dp[to][0] + w; can.push_back(dp[to][1] - (dp[to][0] + w)); } sort(can.begin(),can.end()); dp[v][0] = dp[v][1] = S; for(int i = 0;i < (int)can.size() && can[i] < 0;i++){ if(i < k){ dp[v][0] += can[i]; } if(i < k - 1) { dp[v][1] += can[i]; } } } vector<long long> minimum_closure_costs(int N,vector<int> U,vector<int> V,vector<int> W) { for(int i = 0;i < N - 1;i++){ g[U[i]].emplace_back(V[i],W[i]); g[V[i]].emplace_back(U[i],W[i]); } vector<ll> res; for(int i = 0;i < N;i++){ k = i; dfs(i); res.push_back(dp[i][0]); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...