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 <bits/stdc++.h>
#define fi first
#define se second
#define nmax 100008
using namespace std;
typedef pair<int, int> pii;
int n;
long long dp[2008][2008];
vector<long long>vt[2008][2008];
vector<pii> l[nmax];
void dfs(int id, int x, int pre){
dp[id][x] = 0;
for (pii it : l[x])
if (it.fi != pre){
dfs(id, it.fi, x);
if (!id)
dp[id][x] += dp[id][it.fi] + it.se;
else{
dp[id][x] += dp[id - 1][it.fi];
vt[id][x].push_back(dp[id][it.fi] + it.se - dp[id - 1][it.fi]);
}
}
sort(vt[id][x].begin(), vt[id][x].end(), greater<long long>());
while (!vt[id][x].empty() && ((int)vt[id][x].size() > id || vt[id][x].back() < 0)){
dp[id][x] += vt[id][x].back();
vt[id][x].pop_back();
}
}
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
assert((n = N) <= 2000);
for (int i = 0; i < n - 1; i++){
l[U[i]].push_back({V[i], W[i]});
l[V[i]].push_back({U[i], W[i]});
}
vector<long long>res;
for (int k = 0; k < n; k++){
dfs(k, 0, 0);
res.push_back(dp[k][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... |