Submission #742685

# Submission time Handle Problem Language Result Execution time Memory
742685 2023-05-16T17:32:40 Z Jarif_Rahman Road Closures (APIO21_roads) C++17
0 / 100
50 ms 6416 KB
#include "roads.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int n, k;

vector<ll> minimum_closure_costs(int _n, vector<int> U, vector<int> V, vector<int> W){
    swap(n, _n);
    vector<int> inital_deg(n, 0);

    for(int i = 0; i < n-1; i++) inital_deg[U[i]]++, inital_deg[V[i]]++;

    vector<int> o(n);
    vector<pair<int, int>> edges;
    for(int i = 0; i < n; i++) o[i] = i;
    for(int i = 0; i < n-1; i++) edges.pb({U[i], V[i]});

    sort(o.begin(), o.end(), [&](int a, int b){
        return inital_deg[a] > inital_deg[b];
    });
    sort(edges.begin(), edges.end(), [&](pair<int, int> a, pair<int, int> b){
        return min(inital_deg[a.f], inital_deg[a.sc]) > min(inital_deg[b.f], inital_deg[b.sc]);
    });

    vector<int> deg(n, 0);
    vector<ll> ans(n, 0);

    for(k = n-1; k >= 0; k--){
        int cur = 0, ex = 0;
        for(int i = 0; i < n; i++){
            if(inital_deg[o[i]] <= k) break;
            deg[o[i]] = inital_deg[o[i]];
            ex+=inital_deg[o[i]]-k;
        }
        for(int i = 0; i < n-1; i++){
            auto [a, b] = edges[i];
            if(min(inital_deg[a], inital_deg[b]) <= k) break;
            if(min(deg[a], deg[b]) > k) ex-=2, cur++, deg[a]--, deg[b]--;
        }
        cur+=ex;
        ans[k] = cur;
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 6416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 6416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -