Submission #985473

# Submission time Handle Problem Language Result Execution time Memory
985473 2024-05-17T23:32:35 Z shjeong Road Closures (APIO21_roads) C++17
0 / 100
51 ms 19316 KB
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <vector>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <cassert>
#include <list>
using namespace std;
#define all(x) x.begin(), x.end()
#define rll(x) x.rbegin(), x.rend()
#define comp(x) x.erase(unique(all(x)), x.end())
#define MOD 1000000007
#define MOD2 998244353
#define debug(x) cout << #x<<" is "<<x<<"\n";
#define X first
#define Y second
#define DEB cout<<"[DEBUG]"
#define PAIR(a,b) "("<<a<<", "<<b<<")"
#define PRINT1(V) DEB<<#V<<endl; for(auto i : V)DEB<<i<<"\n"
#define PRINT2(V) DEB<<#V<<endl; for(auto [a,b] : V)DEB<<PAIR(a,b)<<"\n";
typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef pair<ld,ll> Pd;
ll dp[2020][2];
ll deg[202020];
ll par[202020];
ll n, k;
vector<P> adj[202020];
void dfs(ll cur, ll prv=-1){
    priority_queue<ll> pq;
    for(auto [next,w] : adj[cur])if(prv!=next){
        dfs(next,cur);
        if(dp[next][0] < dp[next][1] + w)pq.push(dp[next][1] + w - dp[next][0]);
        dp[cur][0] += dp[next][0], dp[cur][1] += dp[next][0];
    }
    vector<ll> v;
    ll pqsiz = pq.size();
    for(int i = 0 ; i < min<ll>(pqsiz, k) ; i++)v.push_back(pq.top()), pq.pop();
    for(int i = 0 ; i < min<ll>(v.size(), k) ; i++)dp[cur][0] += v[i];
    for(int i = 0 ; i < min<ll>(v.size(), k-1) ; i++)dp[cur][1] += v[i];
}
void dfs2(ll cur, ll prv=-1){
    par[cur] = prv;
    for(auto [next,w] : adj[cur])if(prv!=next)dfs2(next,cur);
}
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    vector<ll> ret(N);
    n=N;
    ll S = 0;
    for(int i = 0 ; i < n-1 ; i++){
        S += W[i];
        adj[U[i]].push_back({V[i],W[i]});
        adj[V[i]].push_back({U[i],W[i]});
        deg[U[i]]++; deg[V[i]]++;
    }
    dfs2(0);
    vector<ll> cur(N);
    iota(cur.begin(),cur.end(),0);
    for(int i = 0 ; i < n ; i++){
        ll res = 0;
        vector<ll> l;
        for(auto j : cur){
            if(j!=0 and deg[j]>i and deg[par[j]]>i){
                l.push_back(j);
                deg[j]--; deg[par[j]]--;
                res++;
            }
        }
        vector<ll> next;
        for(auto j : cur)res += max(deg[j]-i,0LL);
        for(auto j : l)deg[j]++, deg[par[j]]++;
        ret[i] = res;
        for(auto j : cur){
            if(deg[j]>i+1)next.push_back(j);
        }
        cur=next;
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 19316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 19316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -