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 F first
#define S second
using namespace std;
const int N = 1e5+7;
typedef pair<int,int> pii;
vector<int> g[N];
int deg[N];
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U,
std::vector<int> V,
std::vector<int> W) {
vector<long long> ans(N,0);
int n = N;
for(int i = 0 ; i < n-1 ; i++) {
g[U[i]].push_back(V[i]);
g[V[i]].push_back(U[i]);
deg[U[i]]++;
deg[V[i]]++;
}
set<pii> st;
for(int i = 0 ; i < n ; i++) st.insert({-deg[i],i});
int cnt = 0;
for(int i = N-1 ; i >= 0 ; i--) {
while(-(*st.begin()).F > i) {
auto x = *st.begin();
st.erase(st.begin());
cnt++;
int u = x.S;
deg[u]--;
st.insert({-deg[u],u});
pii mx = {-1,-1};
for(auto v:g[u]) {
mx = max(mx,{deg[v],v});
}
st.erase({-mx.F,mx.S});
deg[mx.S]--;
st.insert({-deg[mx.S],mx.S});
}
ans[i] = cnt;
}
return ans;
}
# | 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... |