이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
vector<pii> adj[N];
ll dp[N][2];
int k;
void dfs(int x, int pr = -1){
ll sm = 0;
vector<ll> van;
for(auto [i, w] : adj[x])
if(i != pr){
dfs(i, x);
sm += dp[i][0]+w;
van.pb(dp[i][1]-(dp[i][0]+w));
}
sort(all(van));
dp[x][0] = dp[x][1] = sm;
int n = (int)van.size();
for(int i = 0; i < n and van[i] < 0; ++i){
if(i < k)
dp[x][0] += van[i];
if(i < k - 1)
dp[x][1] += van[i];
}
}
vector<ll> minimum_closure_costs(int n, vector<int> u, vector<int> v, vector<int> w){
for(int i = 0; i < n-1; ++i){
adj[u[i]].pb({v[i], w[i]});
adj[v[i]].pb({u[i], w[i]});
}
vector<ll> A;
for(int i = 0; i < n; ++i){
k = i;
dfs(i);
A.pb(dp[i][0]);
}
return A;
}
# | 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... |