제출 #447572

#제출 시각아이디문제언어결과실행 시간메모리
447572dxz05Split the Attractions (IOI19_split)C++14
18 / 100
105 ms18520 KiB
#include "split.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3e5 + 3e2;

vector<int> perm = {0, 1, 2};

void sort(int &a, int &b, int &c){
    vector<int> v = {a, b, c};
    do {
        a = v[perm[0]], b = v[perm[1]], c = v[perm[2]];
        if (a <= b && b <= c) break;
    } while (next_permutation(perm.begin(), perm.end()));
}

vector<int> orig(vector<int> v){
    if (v[0] == 0) return v;
    vector<int> res = v;
    for (int i = 0; i < v.size(); i++){
        res[i] = perm[v[i] - 1] + 1;
    }
    return res;
}

vector<int> g[MAXN];

bool used[MAXN];

vector<int> ord;
void dfs(int v){
    used[v] = true;
    ord.push_back(v);

    for (int u : g[v]){
        if (!used[u]) dfs(u);
    }
}

int cnt[MAXN];
int par[MAXN];

void dfs1(int v, int p){
    used[v] = true;
    par[v] = p;
    cnt[v] = 1;

    for (int u : g[v]){
        if (!used[u]){
            dfs1(u, v);
            cnt[v] += cnt[u];
        }
    }
}

vector<int> ord2;

void dfs2(int v, int p, int x){
    ord2.push_back(v);
    for (int u : g[v]){
        if (u != p && u != x && cnt[u] < cnt[v]) dfs2(u, v, x);
    }
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	vector<int> res(n, 0);

	sort(a, b, c);

    int m = p.size();

    for (int i = 0; i < m; i++){
        g[p[i]].push_back(q[i]);
        g[q[i]].push_back(p[i]);
    }

    bool sub2 = true;
    for (int i = 0; i < n; i++){
        if (g[i].size() > 2) sub2 = false;
    }

    if (a == 1 || sub2) {
        int ind = 0;
        for (int i = 0; i < n; i++) {
            if (g[i].size() < g[ind].size()) ind = i;
        }

        dfs(ind);

        for (int i = 0; i < n; i++) {
            if (i < a) res[ord[i]] = 1;
            else if (i < a + b) res[ord[i]] = 2;
            else
                res[ord[i]] = 3;
        }

        return orig(res);
    }

    for (int it = 0; it < n; it++) {
        fill(used, used + n, false);
        dfs1(it, it);

        for (int i = 0; i < n; i++) {
            if (cnt[i] < a || n - cnt[i] < b) continue;

            ord2.clear();
            dfs2(i, i, par[i]);

            for (int j = 0; j < a; j++) res[ord2[j]] = 1;

            ord2.clear();
            dfs2(par[i], par[i], i);

            for (int j = 0; j < b; j++) res[ord2[j]] = 2;

            for (int j = 0; j < n; j++) {
                if (res[j] == 0) res[j] = 3;
            }

            return orig(res);
        }

        for (int i = 0; i < n; i++) {
            if (cnt[i] < b || n - cnt[i] < a) continue;

            ord2.clear();
            dfs2(i, i, par[i]);

            for (int j = 0; j < b; j++) res[ord2[j]] = 2;

            ord2.clear();
            dfs2(par[i], par[i], i);

            for (int j = 0; j < a; j++) res[ord2[j]] = 1;

            for (int j = 0; j < n; j++) {
                if (res[j] == 0) res[j] = 3;
            }

            return orig(res);
        }
    }

    return res;
}

/*
7 6
2 2 3
0 1
1 2
2 3
3 4
4 5
5 6
 */

컴파일 시 표준 에러 (stderr) 메시지

split.cpp: In function 'std::vector<int> orig(std::vector<int>)':
split.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < v.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...