Submission #282130

# Submission time Handle Problem Language Result Execution time Memory
282130 2020-08-24T03:36:04 Z hoanghq2004 Split the Attractions (IOI19_split) C++14
40 / 100
177 ms 25848 KB
#include <bits/stdc++.h>

#define split

#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 = 0; 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;
            paint(0, a.first, a.second);
            cnt = n - sz[u];

            queue <int> q;
            for (auto v: E[u])
                if (low[v] < num[u])
                    q.push(v);
            stack <int> stk;
            while (!q.empty())
            {
                int u = q.front();
                q.pop();
                stk.push(u);
                for (auto v: E[u])
                    if (!C[v])
                        q.push(v);
            }
            while (!stk.empty())
            {
                int u = stk.top();
                stk.pop();
                C[u] = a.second;
                ++cnt;
                if (cnt == a.first) break;
            }
            C[u] = 0;
            paint(u, b.first, b.second);
            for (int i = 0; i < n; ++i)
                if (!C[i]) C[i] = c.second;
            return C;
        }
    }
    return C;
}

#ifndef split
int main() {
    freopen("split.inp", "r", stdin);
    freopen("split.out", "w", stdout);


	int n, m, a, b, c;
	assert(5 == scanf("%d%d%d%d%d", &n, &m, &a, &b, &c));
	vector <int> p(m), q(m);
	for (int i = 0; i < m; ++i)
		assert(2 == scanf("%d%d", &p[i], &q[i]));

	vector <int> result = find_split(n, a, b, c, p, q);

	for (int i = 0; i < result.size(); ++i)
		printf("%s%d", ((i > 0) ? " " : ""), result[i]);
	printf("\n");
	return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 3 ms 4992 KB ok, correct split
3 Correct 5 ms 4992 KB ok, correct split
4 Correct 3 ms 4992 KB ok, correct split
5 Correct 5 ms 4992 KB ok, correct split
6 Correct 4 ms 4992 KB ok, correct split
7 Correct 123 ms 25208 KB ok, correct split
8 Correct 117 ms 22648 KB ok, correct split
9 Correct 121 ms 21752 KB ok, correct split
10 Correct 127 ms 25720 KB ok, correct split
11 Correct 133 ms 25848 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 4 ms 5024 KB ok, correct split
3 Correct 3 ms 4992 KB ok, correct split
4 Correct 157 ms 21240 KB ok, correct split
5 Correct 111 ms 14968 KB ok, correct split
6 Correct 135 ms 25720 KB ok, correct split
7 Correct 134 ms 22284 KB ok, correct split
8 Correct 177 ms 18680 KB ok, correct split
9 Correct 120 ms 16376 KB ok, correct split
10 Correct 77 ms 13808 KB ok, correct split
11 Correct 73 ms 13808 KB ok, correct split
12 Correct 69 ms 14192 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 104 ms 14968 KB ok, correct split
3 Correct 37 ms 8952 KB ok, correct split
4 Correct 4 ms 4992 KB ok, correct split
5 Correct 120 ms 19540 KB ok, correct split
6 Correct 117 ms 19192 KB ok, correct split
7 Correct 122 ms 18936 KB ok, correct split
8 Correct 120 ms 20600 KB ok, correct split
9 Correct 115 ms 18680 KB ok, correct split
10 Correct 30 ms 8448 KB ok, no valid answer
11 Correct 44 ms 9984 KB ok, no valid answer
12 Correct 82 ms 14324 KB ok, no valid answer
13 Correct 100 ms 14828 KB ok, no valid answer
14 Correct 67 ms 14192 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB ok, correct split
2 Correct 4 ms 4992 KB ok, no valid answer
3 Correct 4 ms 4992 KB ok, correct split
4 Correct 4 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 3 ms 4992 KB ok, correct split
8 Correct 4 ms 4992 KB ok, correct split
9 Correct 6 ms 5376 KB ok, correct split
10 Correct 6 ms 5340 KB ok, correct split
11 Correct 4 ms 4992 KB ok, correct split
12 Correct 6 ms 5376 KB ok, correct split
13 Correct 3 ms 4992 KB ok, correct split
14 Correct 4 ms 4992 KB ok, correct split
15 Correct 3 ms 4992 KB ok, correct split
16 Correct 3 ms 4992 KB ok, correct split
17 Correct 4 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 4 ms 5120 KB ok, correct split
21 Correct 5 ms 5376 KB ok, correct split
22 Correct 5 ms 5376 KB ok, correct split
23 Correct 5 ms 5376 KB ok, correct split
24 Correct 6 ms 5376 KB ok, correct split
25 Correct 5 ms 5376 KB ok, correct split
26 Correct 6 ms 5376 KB ok, correct split
27 Correct 6 ms 5376 KB ok, correct split
28 Correct 6 ms 5376 KB ok, correct split
29 Correct 4 ms 5120 KB ok, correct split
30 Correct 6 ms 5376 KB ok, correct split
31 Correct 5 ms 5120 KB ok, correct split
32 Correct 4 ms 4992 KB ok, correct split
33 Correct 4 ms 5120 KB ok, correct split
34 Incorrect 5 ms 5248 KB 2 components are not connected
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB ok, correct split
2 Correct 3 ms 4992 KB ok, correct split
3 Correct 5 ms 4992 KB ok, correct split
4 Correct 3 ms 4992 KB ok, correct split
5 Correct 5 ms 4992 KB ok, correct split
6 Correct 4 ms 4992 KB ok, correct split
7 Correct 123 ms 25208 KB ok, correct split
8 Correct 117 ms 22648 KB ok, correct split
9 Correct 121 ms 21752 KB ok, correct split
10 Correct 127 ms 25720 KB ok, correct split
11 Correct 133 ms 25848 KB ok, correct split
12 Correct 4 ms 4992 KB ok, correct split
13 Correct 4 ms 5024 KB ok, correct split
14 Correct 3 ms 4992 KB ok, correct split
15 Correct 157 ms 21240 KB ok, correct split
16 Correct 111 ms 14968 KB ok, correct split
17 Correct 135 ms 25720 KB ok, correct split
18 Correct 134 ms 22284 KB ok, correct split
19 Correct 177 ms 18680 KB ok, correct split
20 Correct 120 ms 16376 KB ok, correct split
21 Correct 77 ms 13808 KB ok, correct split
22 Correct 73 ms 13808 KB ok, correct split
23 Correct 69 ms 14192 KB ok, correct split
24 Correct 4 ms 4992 KB ok, correct split
25 Correct 104 ms 14968 KB ok, correct split
26 Correct 37 ms 8952 KB ok, correct split
27 Correct 4 ms 4992 KB ok, correct split
28 Correct 120 ms 19540 KB ok, correct split
29 Correct 117 ms 19192 KB ok, correct split
30 Correct 122 ms 18936 KB ok, correct split
31 Correct 120 ms 20600 KB ok, correct split
32 Correct 115 ms 18680 KB ok, correct split
33 Correct 30 ms 8448 KB ok, no valid answer
34 Correct 44 ms 9984 KB ok, no valid answer
35 Correct 82 ms 14324 KB ok, no valid answer
36 Correct 100 ms 14828 KB ok, no valid answer
37 Correct 67 ms 14192 KB ok, no valid answer
38 Correct 3 ms 4992 KB ok, correct split
39 Correct 4 ms 4992 KB ok, no valid answer
40 Correct 4 ms 4992 KB ok, correct split
41 Correct 4 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 3 ms 4992 KB ok, correct split
45 Correct 4 ms 4992 KB ok, correct split
46 Correct 6 ms 5376 KB ok, correct split
47 Correct 6 ms 5340 KB ok, correct split
48 Correct 4 ms 4992 KB ok, correct split
49 Correct 6 ms 5376 KB ok, correct split
50 Correct 3 ms 4992 KB ok, correct split
51 Correct 4 ms 4992 KB ok, correct split
52 Correct 3 ms 4992 KB ok, correct split
53 Correct 3 ms 4992 KB ok, correct split
54 Correct 4 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 4 ms 5120 KB ok, correct split
58 Correct 5 ms 5376 KB ok, correct split
59 Correct 5 ms 5376 KB ok, correct split
60 Correct 5 ms 5376 KB ok, correct split
61 Correct 6 ms 5376 KB ok, correct split
62 Correct 5 ms 5376 KB ok, correct split
63 Correct 6 ms 5376 KB ok, correct split
64 Correct 6 ms 5376 KB ok, correct split
65 Correct 6 ms 5376 KB ok, correct split
66 Correct 4 ms 5120 KB ok, correct split
67 Correct 6 ms 5376 KB ok, correct split
68 Correct 5 ms 5120 KB ok, correct split
69 Correct 4 ms 4992 KB ok, correct split
70 Correct 4 ms 5120 KB ok, correct split
71 Incorrect 5 ms 5248 KB 2 components are not connected
72 Halted 0 ms 0 KB -