This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |