답안 #143905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143905 2019-08-15T12:35:20 Z onjo0127 Split the Attractions (IOI19_split) C++14
40 / 100
194 ms 19192 KB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;

const int MXN = 100009;
bool vs[MXN];
vector<int> G[MXN], T[MXN];
int N, M, F1 = 1, F2 = 2, F3 = 3, A, B, C, sz[MXN], P[MXN], ans[MXN], cent, U[MXN], S[MXN];

int root(int x) {
    if(U[x] == x) return x;
    return U[x] = root(U[x]);
}

void merg(int u, int v) {
    u = root(u); v = root(v);
    if(u != v) U[u] = v, S[v] += S[u];
}

void dfs1(int x) {
    vs[x] = 1; sz[x] = 1;
    for(auto& it: G[x]) if(!vs[it]) {
        dfs1(it);
        sz[x] += sz[it];
        T[x].push_back(it);
        T[it].push_back(x);
    }
}

int fnd(int rt, int x) {
    int mxi = -1;
    for(auto &it: T[x]) {
        if(sz[it] > sz[x]) continue;
        if(mxi == -1 || sz[mxi] < sz[it]) mxi = it;
    }
    if(mxi == -1 || sz[mxi] * 2 <= sz[rt]) return x;
    return fnd(rt, mxi);
}

void dfs2(int x, int p) {
    sz[x] = 1; P[x] = p;
    for(auto& it: T[x]) if(it != p) {
        dfs2(it, x);
        sz[x] += sz[it];
    }
}

int lft;
void grd(int x, int p, int bck, int col) {
    if(!lft || ans[x]) return;
    ans[x] = col; --lft;
    if(bck) for(auto& it: G[x]) grd(it, x, bck, col);
    else for(auto& it: T[x]) if(it != p) grd(it, x, bck, col);
}

vector<int> makeans(bool fail) {
    if(fail) {
        vector<int> res(N, 0);
        return res;
    }
    vector<int> res(N, F3);
    for(int i=0; i<N; i++) {
        if(ans[i] == 1) res[i] = F1;
        if(ans[i] == 2) res[i] = F2;
    }
    return res;
}

void bfs(int st) {
    int cnt = 0;
    deque<int> que; que.push_back(st); ans[st] = -1;
    while(cnt < A) {
        int x = que.front(); que.pop_front();
        ans[x] = 1; ++cnt;
        for(auto& it: T[x]) {
            if(it == cent) continue;
            if(!ans[it]) {
                ans[it] = -1;
                que.push_front(it);
            }
        }
        for(auto& it: G[x]) {
            if(it == cent) continue;
            if(!ans[it]) {
                ans[it] = -1;
                que.push_back(it);
            }
        }
    }
    for(int i=0; i<N; i++) if(ans[i] == -1) ans[i] = 0;
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	if(a > b) swap(a, b), swap(F1, F2);
	if(a > c) swap(a, c), swap(F1, F3);
    if(b > c) swap(b, c), swap(F2, F3);
    A = a; B = b; C = c; N = n; M = p.size();
    for(int i=0; i<M; i++) {
        G[p[i]].push_back(q[i]);
        G[q[i]].push_back(p[i]);
    }
    dfs1(0);
    cent = fnd(0, 0);
    dfs2(cent, cent);
    for(int i=0; i<N; i++) {
        if(i == cent) continue;
        if(sz[i] >= A && N - sz[i] >= B) {
            lft = A; grd(i, P[i], 0, 1);
            lft = B; grd(P[i], P[i], 1, 2);
            return makeans(0);
        }
    }
    for(int i=0; i<N; i++) S[i] = 1, U[i] = i;
    for(int i=0; i<M; i++) {
        if(p[i] == cent || q[i] == cent) continue;
        merg(p[i], q[i]);
    }
    int st = -1;
    for(auto& it: T[cent]) if(S[root(it)] >= A) st = it;
    if(st == -1) return makeans(1);
    bfs(st);
    lft = B; grd(cent, cent, 1, 2);
	return makeans(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB ok, correct split
2 Correct 6 ms 4984 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 6 ms 4984 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Correct 6 ms 5112 KB ok, correct split
7 Correct 147 ms 19020 KB ok, correct split
8 Correct 135 ms 17276 KB ok, correct split
9 Correct 159 ms 17300 KB ok, correct split
10 Correct 133 ms 18780 KB ok, correct split
11 Correct 147 ms 19192 KB ok, correct split
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB ok, correct split
2 Correct 6 ms 5112 KB ok, correct split
3 Correct 6 ms 4984 KB ok, correct split
4 Correct 164 ms 17400 KB ok, correct split
5 Correct 133 ms 14808 KB ok, correct split
6 Correct 128 ms 18812 KB ok, correct split
7 Correct 146 ms 17584 KB ok, correct split
8 Correct 194 ms 16760 KB ok, correct split
9 Correct 143 ms 14712 KB ok, correct split
10 Correct 94 ms 15344 KB ok, correct split
11 Correct 92 ms 15344 KB ok, correct split
12 Correct 100 ms 15344 KB ok, correct split
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB ok, correct split
2 Correct 135 ms 14712 KB ok, correct split
3 Correct 45 ms 8952 KB ok, correct split
4 Correct 6 ms 5112 KB ok, correct split
5 Correct 147 ms 16120 KB ok, correct split
6 Correct 137 ms 15864 KB ok, correct split
7 Correct 132 ms 15992 KB ok, correct split
8 Correct 140 ms 16632 KB ok, correct split
9 Correct 138 ms 15992 KB ok, correct split
10 Correct 52 ms 8440 KB ok, no valid answer
11 Correct 58 ms 10104 KB ok, no valid answer
12 Correct 116 ms 15476 KB ok, no valid answer
13 Correct 131 ms 15224 KB ok, no valid answer
14 Correct 111 ms 15704 KB ok, no valid answer
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB ok, correct split
2 Correct 6 ms 4988 KB ok, no valid answer
3 Correct 6 ms 4984 KB ok, correct split
4 Correct 6 ms 5112 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Correct 6 ms 5112 KB ok, correct split
7 Correct 6 ms 5112 KB ok, correct split
8 Correct 6 ms 5112 KB ok, correct split
9 Correct 9 ms 5368 KB ok, correct split
10 Correct 9 ms 5368 KB ok, correct split
11 Correct 6 ms 4984 KB ok, correct split
12 Correct 9 ms 5368 KB ok, correct split
13 Correct 6 ms 4984 KB ok, correct split
14 Correct 6 ms 5112 KB ok, correct split
15 Correct 6 ms 4984 KB ok, correct split
16 Correct 6 ms 4984 KB ok, correct split
17 Correct 6 ms 4984 KB ok, correct split
18 Correct 6 ms 4984 KB ok, correct split
19 Correct 6 ms 5112 KB ok, correct split
20 Correct 7 ms 5104 KB ok, correct split
21 Correct 8 ms 5240 KB ok, correct split
22 Correct 8 ms 5372 KB ok, correct split
23 Correct 10 ms 5368 KB ok, correct split
24 Correct 8 ms 5240 KB ok, correct split
25 Correct 8 ms 5240 KB ok, correct split
26 Correct 9 ms 5372 KB ok, correct split
27 Correct 9 ms 5368 KB ok, correct split
28 Correct 9 ms 5368 KB ok, correct split
29 Correct 6 ms 5112 KB ok, correct split
30 Correct 9 ms 5368 KB ok, correct split
31 Correct 7 ms 5112 KB ok, correct split
32 Correct 7 ms 4984 KB ok, correct split
33 Correct 6 ms 5112 KB ok, correct split
34 Correct 8 ms 5368 KB ok, correct split
35 Correct 9 ms 5240 KB ok, correct split
36 Correct 8 ms 5368 KB ok, correct split
37 Incorrect 9 ms 5368 KB invalid split: #1=1523, #2=833, #3=144
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB ok, correct split
2 Correct 6 ms 4984 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 6 ms 4984 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Correct 6 ms 5112 KB ok, correct split
7 Correct 147 ms 19020 KB ok, correct split
8 Correct 135 ms 17276 KB ok, correct split
9 Correct 159 ms 17300 KB ok, correct split
10 Correct 133 ms 18780 KB ok, correct split
11 Correct 147 ms 19192 KB ok, correct split
12 Correct 6 ms 4984 KB ok, correct split
13 Correct 6 ms 5112 KB ok, correct split
14 Correct 6 ms 4984 KB ok, correct split
15 Correct 164 ms 17400 KB ok, correct split
16 Correct 133 ms 14808 KB ok, correct split
17 Correct 128 ms 18812 KB ok, correct split
18 Correct 146 ms 17584 KB ok, correct split
19 Correct 194 ms 16760 KB ok, correct split
20 Correct 143 ms 14712 KB ok, correct split
21 Correct 94 ms 15344 KB ok, correct split
22 Correct 92 ms 15344 KB ok, correct split
23 Correct 100 ms 15344 KB ok, correct split
24 Correct 6 ms 4984 KB ok, correct split
25 Correct 135 ms 14712 KB ok, correct split
26 Correct 45 ms 8952 KB ok, correct split
27 Correct 6 ms 5112 KB ok, correct split
28 Correct 147 ms 16120 KB ok, correct split
29 Correct 137 ms 15864 KB ok, correct split
30 Correct 132 ms 15992 KB ok, correct split
31 Correct 140 ms 16632 KB ok, correct split
32 Correct 138 ms 15992 KB ok, correct split
33 Correct 52 ms 8440 KB ok, no valid answer
34 Correct 58 ms 10104 KB ok, no valid answer
35 Correct 116 ms 15476 KB ok, no valid answer
36 Correct 131 ms 15224 KB ok, no valid answer
37 Correct 111 ms 15704 KB ok, no valid answer
38 Correct 6 ms 4984 KB ok, correct split
39 Correct 6 ms 4988 KB ok, no valid answer
40 Correct 6 ms 4984 KB ok, correct split
41 Correct 6 ms 5112 KB ok, correct split
42 Correct 6 ms 5112 KB ok, correct split
43 Correct 6 ms 5112 KB ok, correct split
44 Correct 6 ms 5112 KB ok, correct split
45 Correct 6 ms 5112 KB ok, correct split
46 Correct 9 ms 5368 KB ok, correct split
47 Correct 9 ms 5368 KB ok, correct split
48 Correct 6 ms 4984 KB ok, correct split
49 Correct 9 ms 5368 KB ok, correct split
50 Correct 6 ms 4984 KB ok, correct split
51 Correct 6 ms 5112 KB ok, correct split
52 Correct 6 ms 4984 KB ok, correct split
53 Correct 6 ms 4984 KB ok, correct split
54 Correct 6 ms 4984 KB ok, correct split
55 Correct 6 ms 4984 KB ok, correct split
56 Correct 6 ms 5112 KB ok, correct split
57 Correct 7 ms 5104 KB ok, correct split
58 Correct 8 ms 5240 KB ok, correct split
59 Correct 8 ms 5372 KB ok, correct split
60 Correct 10 ms 5368 KB ok, correct split
61 Correct 8 ms 5240 KB ok, correct split
62 Correct 8 ms 5240 KB ok, correct split
63 Correct 9 ms 5372 KB ok, correct split
64 Correct 9 ms 5368 KB ok, correct split
65 Correct 9 ms 5368 KB ok, correct split
66 Correct 6 ms 5112 KB ok, correct split
67 Correct 9 ms 5368 KB ok, correct split
68 Correct 7 ms 5112 KB ok, correct split
69 Correct 7 ms 4984 KB ok, correct split
70 Correct 6 ms 5112 KB ok, correct split
71 Correct 8 ms 5368 KB ok, correct split
72 Correct 9 ms 5240 KB ok, correct split
73 Correct 8 ms 5368 KB ok, correct split
74 Incorrect 9 ms 5368 KB invalid split: #1=1523, #2=833, #3=144
75 Halted 0 ms 0 KB -