제출 #970827

#제출 시각아이디문제언어결과실행 시간메모리
970827AlperenT_도로 폐쇄 (APIO21_roads)C++17
0 / 100
2083 ms47876 KiB
#include "roads.h" #include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #define pb push_back #define F first #define S second #define ld long double #define aint(a) a.begin(),a.end() #define pii pair <int,int> #define PII pair<pii , pii> #define ll long long #define sz(v) (int)v.size() #define rep(i , a , b) for(int i=a;i <= (b);i++) #define per(i , a , b) for(int i=a;i >= (b);i--) #define deb(x) cout <<#x << " : " << x << "\n" ; using namespace std ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn = 1e6 , maxq = 32, inf = 1e15+10 , lg = 19 ,sq = 707 ,mod = 998244353 ; vector <pii> G[maxn] ; ll dp[maxn][2] , k; void dfs(int v, int p = -1){ dp[v][0] = dp[v][1] = 0; int x = max(0ll,sz(G[v])-k) ; priority_queue <ll> pq ; for(auto [u,w] : G[v]){ if(u == p)continue ; dfs(u , v) ; dp[v][0] += dp[u][1] ; pq.push((-dp[u][1] + dp[u][0] + 1ll*w)); while(sz(pq) > x)pq.pop(); } dp[v][1] = dp[v][0] ; if(x==0)return ; if(sz(pq) < x){ dp[v][1] = inf ; while(sz(pq)){ dp[v][0] += pq.top() ; pq.pop() ; } }else{ while(sz(pq)){ ll z = pq.top() ;pq.pop() ; if(sz(pq) != 0)dp[v][0] += z ; dp[v][1] += z; } } } vector<ll> minimum_closure_costs(int n, vector<int> U,vector<int> V,vector<int> W) { rep(i ,0 , n-2){ G[V[i]].pb({U[i] , W[i]}) ; G[U[i]].pb({V[i] , W[i]}) ; } vector<ll> ans ; rep(i , 0 , n-1){ k = i ;dfs(0); ans.pb(dp[0][1]); } return ans ; }
#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...