답안 #281774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281774 2020-08-23T12:59:16 Z hoanghq2004 Split the Attractions (IOI19_split) C++14
40 / 100
172 ms 24616 KB
#include <bits/stdc++.h>
#include "split.h"

using namespace std;
const int N = 100005;
int n;
pair <int, int> a, b, c;
vector <int> C, adj[N], E[N];
int sz[N], check[N];
int times, low[N], num[N];

void dfs(int u, int p)
{
    num[u] = low[u] = ++times;
    sz[u] = 1;
    check[u] = 1;
    for (auto v: adj[u])
    {
        if (v == p) continue;
        if (!num[v])
        {
            E[u].push_back(v);
            dfs(v, u);
            sz[u] += sz[v];
            low[u] = min(low[u], low[v]);
            if (sz[v] >= a.first) check[u] = 0;
        }
        else low[u] = min(low[u], num[v]);
    }
}


void paint(int u, int num, int cl)
{
    queue <int> q;
    q.push(u);
    int cnt = 0;
    if (!C[u])
    {
        C[u] = cl;
        cnt = 1;
    }
    if (cnt == num) return;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (auto v: E[u])
            if (!C[v])
            {
                ++cnt;
                C[v] = cl;
                q.push(v);
                if (num == cnt) return;
            }
    }
}


vector <int> find_split(int _n, int _a, int _b, int _c, vector <int> u, vector <int> v)
{
    n = _n;
    a = {_a, 1}, b = {_b, 2}, c = {_c, 3};

    if (a > b) swap(a, b);
    if (a > c) swap(a, c);
    if (b > c) swap(b, c);

    assert(a <= b && b <= c);

    int m = (int)v.size();
    C = vector <int> (n, 0);

    for (int i = 0; i < m; i ++)
    {
        adj[v[i]].push_back(u[i]);
        adj[u[i]].push_back(v[i]);
    }
    dfs(0, 0);
    for (int u = 1; u < n; ++u)
    {
        if (check[u] && sz[u] >= a.first && n - sz[u] >= a.first)
        {
            if (sz[u] <= n - sz[u])
            {
                paint(u, a.first, a.second);
                paint(0, b.first, b.second);
            }
            else
            {
                paint(u, b.first, b.second);
                paint(0, a.first, a.second);
            }
            for (int i = 0; i < n; ++i)
                if (!C[i]) C[i] = c.second;
            return C;
        }
        if (check[u] && n - sz[u] < a.first)
        {
            int cnt = 0;
            for (auto v: E[u])
                if (low[v] < num[u]) cnt += sz[v];
            if (cnt + n - sz[u] < a.first) continue;

            C[u] = b.second;
            cnt = 1;
            for (auto v: E[u])
                if (low[v] >= num[u])
                {
                    paint(v, b.first - cnt, b.second);
                    cnt += sz[v];
                    if (sz[v] <= 0) break;
                }
            paint(0, a.first, a.first);
            cnt = n - sz[u];
            for (int i = 0; i < n; ++i)
                if (!C[i] && low[i] < num[u])
                {
                    C[i] = a.second;
                    ++cnt;
                    if (cnt == a.first) break;
                }
            for (int i = 0; i < n; ++i)
                if (!C[i]) C[i] = c.second;
            return C;
        }
    }
    return C;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 3 ms 4992 KB ok, correct split
3 Correct 4 ms 4992 KB ok, correct split
4 Correct 3 ms 4992 KB ok, correct split
5 Correct 4 ms 4992 KB ok, correct split
6 Correct 5 ms 4992 KB ok, correct split
7 Correct 122 ms 24184 KB ok, correct split
8 Correct 122 ms 21472 KB ok, correct split
9 Correct 128 ms 20576 KB ok, correct split
10 Correct 147 ms 24568 KB ok, correct split
11 Correct 132 ms 24572 KB ok, correct split
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 3 ms 4992 KB ok, correct split
3 Correct 4 ms 5024 KB ok, correct split
4 Correct 137 ms 19536 KB ok, correct split
5 Correct 114 ms 13816 KB ok, correct split
6 Correct 126 ms 24616 KB ok, correct split
7 Correct 129 ms 21184 KB ok, correct split
8 Correct 172 ms 16376 KB ok, correct split
9 Correct 118 ms 15352 KB ok, correct split
10 Correct 67 ms 13040 KB ok, correct split
11 Correct 80 ms 13040 KB ok, correct split
12 Correct 70 ms 13040 KB ok, correct split
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5044 KB ok, correct split
2 Correct 109 ms 13884 KB ok, correct split
3 Correct 41 ms 8576 KB ok, correct split
4 Correct 3 ms 4992 KB ok, correct split
5 Correct 132 ms 18296 KB ok, correct split
6 Correct 128 ms 18044 KB ok, correct split
7 Correct 141 ms 17912 KB ok, correct split
8 Correct 128 ms 19448 KB ok, correct split
9 Correct 116 ms 17528 KB ok, correct split
10 Correct 30 ms 7936 KB ok, no valid answer
11 Correct 58 ms 9436 KB ok, no valid answer
12 Correct 80 ms 13172 KB ok, no valid answer
13 Correct 108 ms 13688 KB ok, no valid answer
14 Correct 70 ms 12944 KB ok, no valid answer
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB ok, correct split
2 Correct 3 ms 4992 KB ok, no valid answer
3 Correct 4 ms 4992 KB ok, correct split
4 Correct 3 ms 4992 KB ok, correct split
5 Correct 4 ms 4992 KB ok, correct split
6 Correct 3 ms 4992 KB ok, correct split
7 Correct 4 ms 4992 KB ok, correct split
8 Correct 3 ms 4992 KB ok, correct split
9 Correct 6 ms 5376 KB ok, correct split
10 Correct 6 ms 5248 KB ok, correct split
11 Correct 4 ms 4992 KB ok, correct split
12 Correct 6 ms 5376 KB ok, correct split
13 Correct 4 ms 4992 KB ok, correct split
14 Correct 3 ms 4992 KB ok, correct split
15 Correct 4 ms 4992 KB ok, correct split
16 Correct 3 ms 4992 KB ok, correct split
17 Correct 3 ms 4992 KB ok, correct split
18 Correct 3 ms 4992 KB ok, correct split
19 Correct 4 ms 5120 KB ok, correct split
20 Correct 5 ms 5248 KB ok, correct split
21 Correct 5 ms 5376 KB ok, correct split
22 Correct 5 ms 5504 KB ok, correct split
23 Correct 6 ms 5376 KB ok, correct split
24 Correct 5 ms 5376 KB ok, correct split
25 Correct 6 ms 5376 KB ok, correct split
26 Incorrect 7 ms 5248 KB answer for 0-th vertex does not belong to {0, 1, 2, 3}
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 3 ms 4992 KB ok, correct split
3 Correct 4 ms 4992 KB ok, correct split
4 Correct 3 ms 4992 KB ok, correct split
5 Correct 4 ms 4992 KB ok, correct split
6 Correct 5 ms 4992 KB ok, correct split
7 Correct 122 ms 24184 KB ok, correct split
8 Correct 122 ms 21472 KB ok, correct split
9 Correct 128 ms 20576 KB ok, correct split
10 Correct 147 ms 24568 KB ok, correct split
11 Correct 132 ms 24572 KB ok, correct split
12 Correct 4 ms 4992 KB ok, correct split
13 Correct 3 ms 4992 KB ok, correct split
14 Correct 4 ms 5024 KB ok, correct split
15 Correct 137 ms 19536 KB ok, correct split
16 Correct 114 ms 13816 KB ok, correct split
17 Correct 126 ms 24616 KB ok, correct split
18 Correct 129 ms 21184 KB ok, correct split
19 Correct 172 ms 16376 KB ok, correct split
20 Correct 118 ms 15352 KB ok, correct split
21 Correct 67 ms 13040 KB ok, correct split
22 Correct 80 ms 13040 KB ok, correct split
23 Correct 70 ms 13040 KB ok, correct split
24 Correct 4 ms 5044 KB ok, correct split
25 Correct 109 ms 13884 KB ok, correct split
26 Correct 41 ms 8576 KB ok, correct split
27 Correct 3 ms 4992 KB ok, correct split
28 Correct 132 ms 18296 KB ok, correct split
29 Correct 128 ms 18044 KB ok, correct split
30 Correct 141 ms 17912 KB ok, correct split
31 Correct 128 ms 19448 KB ok, correct split
32 Correct 116 ms 17528 KB ok, correct split
33 Correct 30 ms 7936 KB ok, no valid answer
34 Correct 58 ms 9436 KB ok, no valid answer
35 Correct 80 ms 13172 KB ok, no valid answer
36 Correct 108 ms 13688 KB ok, no valid answer
37 Correct 70 ms 12944 KB ok, no valid answer
38 Correct 3 ms 4992 KB ok, correct split
39 Correct 3 ms 4992 KB ok, no valid answer
40 Correct 4 ms 4992 KB ok, correct split
41 Correct 3 ms 4992 KB ok, correct split
42 Correct 4 ms 4992 KB ok, correct split
43 Correct 3 ms 4992 KB ok, correct split
44 Correct 4 ms 4992 KB ok, correct split
45 Correct 3 ms 4992 KB ok, correct split
46 Correct 6 ms 5376 KB ok, correct split
47 Correct 6 ms 5248 KB ok, correct split
48 Correct 4 ms 4992 KB ok, correct split
49 Correct 6 ms 5376 KB ok, correct split
50 Correct 4 ms 4992 KB ok, correct split
51 Correct 3 ms 4992 KB ok, correct split
52 Correct 4 ms 4992 KB ok, correct split
53 Correct 3 ms 4992 KB ok, correct split
54 Correct 3 ms 4992 KB ok, correct split
55 Correct 3 ms 4992 KB ok, correct split
56 Correct 4 ms 5120 KB ok, correct split
57 Correct 5 ms 5248 KB ok, correct split
58 Correct 5 ms 5376 KB ok, correct split
59 Correct 5 ms 5504 KB ok, correct split
60 Correct 6 ms 5376 KB ok, correct split
61 Correct 5 ms 5376 KB ok, correct split
62 Correct 6 ms 5376 KB ok, correct split
63 Incorrect 7 ms 5248 KB answer for 0-th vertex does not belong to {0, 1, 2, 3}
64 Halted 0 ms 0 KB -