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>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl
#define MAX 2000
#define des first
#define peso second
vector< pair<lli,lli> > hijos[MAX+2];
lli dp[MAX+2][MAX+2];
lli total;
void DFS(lli pos, lli padre, lli k) {
vector<pair < lli , pair<lli,lli> > > costos;
for (auto h : hijos[pos]) {
if (h.des == padre) continue;
DFS(h.des, pos, k);
costos.push_back({dp[k][h.des]+h.peso-dp[k-1][h.des], {h.des, h.peso}});
}
sort(costos.begin(), costos.end());
lli cont = 0;
for (auto act : costos) {
if (cont+k < costos.size() || act.first < 0) {
dp[k][pos] += dp[k][act.second.first] + act.second.second;
cont++;
}
else dp[k][pos] += dp[k-1][act.second.first];
}
}
void inicial(lli pos, lli padre) {
for(auto h : hijos[pos]) {
if (h.des == padre) continue;
inicial(h.des,pos);
dp[0][pos] += dp[0][h.des] + h.peso;
}
}
std::vector <long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
vector<long long> res (N, 0);
total = 0;
rep(i,0,N-2) {
hijos[ U[i] ].push_back({V[i], W[i]});
hijos[ V[i] ].push_back({U[i], W[i]});
total += W[i];
}
inicial(0,-1);
rep(i,1,N-1) DFS(0,-1,i);
rep(i,0,N-1) res[i] = dp[i][0];
return res;
}
Compilation message (stderr)
roads.cpp: In function 'void DFS(long long int, long long int, long long int)':
roads.cpp:32:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if (cont+k < costos.size() || act.first < 0) {
| ~~~~~~~^~~~~~~~~~~~~~~
# | 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... |