제출 #1060665

#제출 시각아이디문제언어결과실행 시간메모리
1060665KasymK도로 폐쇄 (APIO21_roads)C++17
24 / 100
2094 ms22172 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...