# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737443 | keisuke6 | Road Closures (APIO21_roads) | C++14 | 2078 ms | 20652 KiB |
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 <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
vector<vector<pair<int,int>>> G(100100);
unordered_map<ll,ll> m;
int bor = 0;
ll f(int x, int par, bool p){
if(m.count(2*x+p)) return m[2*x+p];
int ed = p;
vector<ll> S = {};
ll ans = 0;
for(auto y:G[x]){
int u,w;
tie(u,w) = y;
if(par == u) continue;
ans += f(u,x,false)+w;
S.emplace_back(f(u,x,true)-(f(u,x,false)+w));
}
sort(S.begin(),S.end());
int now = 0;
if(ed > bor) return 1e9;
while(ed < bor && now != S.size() && S[now] < 0){
ed++;
ans += S[now];
now++;
}
return m[2*x+p] = ans;
}
std::vector<ll> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
for(int i=0;i<W.size();i++){
G[U[i]].push_back({V[i],W[i]});
G[V[i]].push_back({U[i],W[i]});
}
vector<ll> A = {};
for(int i=0;i<N;i++){
bor = i;
m.clear();
A.push_back(f(0,-1,false));
}
return A;
}
Compilation message (stderr)
# | 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... |