Submission #561716

# Submission time Handle Problem Language Result Execution time Memory
561716 2022-05-13T11:57:04 Z piOOE Road Closures (APIO21_roads) C++17
0 / 100
78 ms 12092 KB
#include "roads.h"

#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)

typedef long long ll;

const int N = 100001;
int A[N], B[N], W[N], n, depth[N];
vector<int> g[N];
bool used[N];
int pp[N], cnt[N];

void dfs(int v, int p) {
    pp[v] = p;
    for (int to: g[v]) {
        if (to != p) {
            depth[to] = depth[v] + 1;
            dfs(to, v);
        }
    }
}

vector<ll> minimum_closure_costs(int nn, vector<int> uu, vector<int> vv, vector<int> ww) {
    n = nn;
    for (int i = 0; i < n - 1; ++i) {
        A[i] = uu[i], B[i] = vv[i], W[i] = ww[i];
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    vector<ll> ans(n);
    if (*max_element(all(W)) == 1) {
        vector<int> ord(n);
        iota(all(ord), 0);
        sort(all(ord), [](int i, int j) {
            return g[i].size() > g[j].size();
        });
        dfs(0, -1);
        for (int k = 0; k < n; ++k) {
            vector<int> now;
            for (int i: ord) {
                if (g[i].size() <= k) break;
                now.push_back(i);
                used[i] = true;
                cnt[i] = g[i].size();
            }
            for (int i: now) {
                if (pp[i] != -1 && used[pp[i]] && cnt[i] > k) {
                    --cnt[pp[i]];
                    --cnt[i];
                    ++ans[k];
                }
            }
            for (int i: now) {
                ans[k] += max(0, cnt[i] - k);
                used[i] = false;
            }
        }
        return ans;
    } else {
        assert(false);
    }
}

Compilation message

roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:45:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |                 if (g[i].size() <= k) break;
      |                     ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 12092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 12092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -