Submission #501846

# Submission time Handle Problem Language Result Execution time Memory
501846 2022-01-04T16:44:01 Z Victor Road Closures (APIO21_roads) C++17
0 / 100
27 ms 7964 KB
// #pragma GCC optimize ("unroll-loops")
 
#include "roads.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
 
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
 
#define umap unordered_map
#define uset unordered_set
 
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
 
const int INF = 1'000'000'007;
 
int n, k;
vii graph[2001];
ll memo[2001][2];
 
void dp(int u, int p) {
    ll sum = 0;
    vi diff;
    trav(edge, graph[u]) if (edge.first != p) {
        int v, w;
        tie(v, w) = edge;
        dp(v, u);
        sum += memo[v][0];
        diff.emplace_back((memo[v][1] + w) - memo[v][0]);
    }
 
    sort(all(diff));
    memo[u][0] = memo[u][1] = -1;
    int need_rem = (sz(graph[u]) + (u != 0)) - k;
    if(sz(diff))assert(diff.back() < INF);
    diff.emplace_back(INF);
    trav(val, diff) {
        if (need_rem <= 1 && val >= 0 && memo[u][1] == -1) memo[u][1] = sum;
        if (need_rem <= 0 && val >= 0 && memo[u][0] == -1) memo[u][0] = sum;
        sum += val;
        --need_rem;
    }
 
    //cout<<"u = "<<u<<' '<<memo[u][0]<<' '<<memo[u][1]<<endl;
}
 
vector<long long> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    vll ans(n, 0);
    rep(i, 0, n - 1) {
        ans[0] += W[i];
        graph[U[i]].emplace_back(V[i], W[i]);
        graph[V[i]].emplace_back(U[i], W[i]);
    }
 
    rep(i, 1, n) {
        k = i;
        dp(0, 0);
        ans[i] = memo[0][0];
    }
    return ans;
}
/*
int main() {
    int N;
    assert(1 == scanf("%d", &N));
 
    vector<int> U(N - 1), V(N - 1), W(N - 1);
    for (int i = 0; i < N - 1; ++i) {
        assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
    }
 
    vector<long long> closure_costs = minimum_closure_costs(N, U, V, W);
    for (int i = 0; i < static_cast<int>(closure_costs.size()); ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%lld", closure_costs[i]);
    }
    printf("\n");
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 27 ms 7964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 27 ms 7964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -