Submission #260212

#TimeUsernameProblemLanguageResultExecution timeMemory
260212dolphingarlicSplit the Attractions (IOI19_split)C++14
40 / 100
122 ms14456 KiB
#include "split.h"

#include <bits/stdc++.h>
using namespace std;

int n, subtree[100000], v = -1, vp = -1;
vector<int> graph[100000];
vector<pair<int, int>> lab;
bool visited[100000];

void find_v(int node = 0, int parent = -1) {
    visited[node] = true;
    subtree[node] = 1;
    for (int i : graph[node]) if (!visited[i]) {
        find_v(i, node);
        subtree[node] += subtree[i];
    }
    if (v == -1 && subtree[node] >= lab[0].first) {
        v = node;
        vp = parent;
    }
}

void label(int node, int parent, int &cnt, int l, vector<int> &v) {
    if (!cnt) return;
    visited[node] = true;
    v[node] = l;
    cnt--;
    for (int i : graph[node]) if (!visited[i] && i != parent) {
        label(i, node, cnt, l, v);
    }
}

vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
    n = N;
    lab = {{a, 1}, {b, 2}, {c, 3}};
    sort(lab.begin(), lab.end());
    for (int i = 0; i < p.size(); i++) {
        graph[p[i]].push_back(q[i]);
        graph[q[i]].push_back(p[i]);
    }

    find_v();
    if (n - subtree[v] < lab[0].first) return vector<int>(n, 0);

    memset(visited, 0, sizeof visited);
    vector<int> ans(n);
    if (2 * subtree[v] > n) swap(lab[0], lab[1]);
    label(v, vp, lab[0].first, lab[0].second, ans);
    label(vp, v, lab[1].first, lab[1].second, ans);
    for (int i = 0; i < n; i++) if (!ans[i]) ans[i] = lab[2].second;
    return ans;
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < p.size(); i++) {
                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...