Submission #488791

# Submission time Handle Problem Language Result Execution time Memory
488791 2021-11-20T13:13:58 Z Theo830 Road Closures (APIO21_roads) C++17
0 / 100
45 ms 19996 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///APIO 2021 vc
#include "roads.h"
vector<vector<ii> >adj;
ll dp[2005][2];
ll solve(ll idx,ll k,ll p,bool ep){
    if(dp[idx][ep] != -1){
        return dp[idx][ep];
    }
    ll ans = INF;
    ll siz = k - ep;
    vll ex;
    ll sum = 0;
    for(auto x:adj[idx]){
        if(x.F != p){
            sum += x.S + solve(x.F,k,idx,0);
            ex.pb(solve(x.F,k,idx,1) - (x.S + solve(x.F,k,idx,0)));
        }
    }
    ans = sum;
    sort(all(ex));
    siz = min(siz,(ll)ex.size());
    f(i,0,siz){
        ans += max(0LL,ex[i]);
    }
    return dp[idx][ep] = ans;
}
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U,std::vector<int> V,std::vector<int> W){
    vll ans;
    adj.assign(N+5,vector<ii>());
    f(i,0,N-1){
        adj[U[i]].pb(ii(V[i],W[i]));
        adj[V[i]].pb(ii(U[i],W[i]));
    }
    f(k,0,N){
        memset(dp,-1,sizeof dp);
        ans.pb(solve(0,k,N + 5,0));
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 19996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 19996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -