이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<pii> l[nmax];
void dfs(int id, int x, int pre){
vector<long long>vt;
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.push_back(dp[id][it.fi] + it.se - dp[id - 1][it.fi]);
}
}
sort(vt.begin(), vt.end(), greater<long long>());
while (!vt.empty() && ((int)vt.size() > id || vt.back() < 0)){
dp[id][x] += vt.back();
vt.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... |