답안 #470287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470287 2021-09-03T11:27:47 Z luciocf Amusement Park (JOI17_amusement_park) C++14
100 / 100
1617 ms 15840 KB
#include <bits/stdc++.h>
#include "Joi.h"

using namespace std;

const int maxn_0 = 2e4+10;

int grau_0[maxn_0], bit_0[maxn_0];

vector<int> grafo_0[maxn_0], grupo_0[maxn_0];

set<int> adj_0[maxn_0];

int pai_0[maxn_0];
bool mark_0[maxn_0];

void get_sp_0(int u)
{
    mark_0[u] = 1;

    for (auto v: grafo_0[u])
    {
        if (!mark_0[v])
        {
            pai_0[v] = u;
            get_sp_0(v);
        }
    }
}

bool connect_0(int u, int v)
{
    return (adj_0[u].find(v) != adj_0[u].end());
}

void dfs_0_0(int u, int p)
{
    if (grupo_0[0].size() < 60)
    {
        bit_0[u] = grupo_0[0].size();
        grupo_0[0].push_back(u);
    }

    for (auto v: grafo_0[u])
        if (v != p)
            dfs_0_0(v, u);
}

void dfs_1(int u, int p)
{
    for (auto v: grafo_0[u])
    {
        if (v == p) continue;

        bool ok = 0;
        for (auto w: grupo_0[u])
            if (w == v)
                ok = 1;

        if (ok)
        {
            for (auto w: grupo_0[u])
                grupo_0[v].push_back(w);

            dfs_1(v, u);
            continue;
        }

        for (auto w1: grupo_0[u])
            for (auto w2: grupo_0[u])
                if (w1 != w2 && connect_0(w1, w2))
                    grau_0[w1]++;

        int out;
        for (auto w: grupo_0[u])
        {
            if (grau_0[w] == 1 && w != u)
            {
                out = w, bit_0[v] = bit_0[w];
                break;
            }
        }

        grupo_0[v].push_back(v);
        for (auto w: grupo_0[u])
            if (w != out)
                grupo_0[v].push_back(w);

        for (auto w1: grupo_0[u])
            for (auto w2: grupo_0[u])
                if (w1 != w2 && connect_0(w1, w2))
                    grau_0[w1]--;

        dfs_1(v, u);
    }  
}

void Joi(int N, int M, int A[], int B[], long long X, int T)
{
    for (int i = 0; i < M; i++)
    {
        grafo_0[A[i]].push_back(B[i]);
        grafo_0[B[i]].push_back(A[i]);
    }

    get_sp_0(0);

    for (int i = 0; i < N; i++)
        grafo_0[i].clear();

    for (int i = 1; i < N; i++)
    {
        grafo_0[i].push_back(pai_0[i]);
        grafo_0[pai_0[i]].push_back(i);

        adj_0[i].insert(pai_0[i]);
        adj_0[pai_0[i]].insert(i);
    }

    dfs_0_0(0, -1);
    dfs_1(0, -1);

    for (int i = 0; i < N; i++)
    {
        if (X & (1ll<<bit_0[i])) MessageBoard(i, 1);
        else MessageBoard(i, 0);
    }
}
#include <bits/stdc++.h>
#include "Ioi.h"

using namespace std;

const int maxn = 2e4+10;

int grau[maxn], bit[maxn];

bool on[61];

vector<int> grafo[maxn], grupo[maxn];

set<int> adj[maxn];

int pai[maxn];
bool mark[maxn];

void get_sp(int u)
{
    mark[u] = 1;

    for (auto v: grafo[u])
    {
        if (!mark[v])
        {
            pai[v] = u;
            get_sp(v);
        }
    }
}

bool connect(int u, int v)
{
    return (adj[u].find(v) != adj[u].end());
}

void dfs_0(int u, int p)
{
    if (grupo[0].size() < 60)
    {
        bit[u] = (int)grupo[0].size();
        grupo[0].push_back(u);
    }

    for (auto v: grafo[u])
        if (v != p)
            dfs_0(v, u);
}

void dfs(int u, int p)
{
    for (auto v: grafo[u])
    {
        if (v == p) continue;

        bool ok = 0;
        for (auto w: grupo[u])
            if (w == v)
                ok = 1;

        if (ok)
        {
            for (auto w: grupo[u])
                grupo[v].push_back(w);

            dfs(v, u);
            continue;
        }

        for (auto w1: grupo[u])
            for (auto w2: grupo[u])
                if (w1 != w2 && connect(w1, w2))
                    grau[w1]++;

        int out;
        for (auto w: grupo[u])
        {
            if (grau[w] == 1 && w != u)
            {
                out = w, bit[v] = bit[w];
                break;
            }
        }

        grupo[v].push_back(v);
        for (auto w: grupo[u])
            if (w != out)
                grupo[v].push_back(w);

        for (auto w1: grupo[u])
            for (auto w2: grupo[u])
                if (w1 != w2 && connect(w1, w2))
                    grau[w1]--;

        dfs(v, u);
    }  
}

void get(int u, int p, int P)
{
    for (auto v: grafo[u])
    {
        if (v == p) continue;

        bool ok = 0;
        for (auto w: grupo[P])
            if (v == w)
                ok = 1;

        if (!ok) continue;

        on[bit[v]] = Move(v);
        get(v, u, P);
        Move(u);
    }
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T)
{
    for (int i = 0; i < M; i++)
    {
        grafo[A[i]].push_back(B[i]);
        grafo[B[i]].push_back(A[i]);
    }

    get_sp(0);

    for (int i = 0; i < N; i++)
        grafo[i].clear();

    for (int i = 1; i < N; i++)
    {
        grafo[i].push_back(pai[i]);
        grafo[pai[i]].push_back(i);

        adj[i].insert(pai[i]);
        adj[pai[i]].insert(i);
    }

    dfs_0(0, -1);
    dfs(0, -1);

    on[bit[P]] = V;
    get(P, -1, P);

    long long ans = 0;
    for (int i = 0; i < 60; i++)
        if (on[i])
            ans += (1ll<<i);

    return ans;
}

Compilation message

Joi.cpp: In function 'void dfs_1(int, int)':
Joi.cpp:86:13: warning: 'out' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |             if (w != out)
      |             ^~

Ioi.cpp: In function 'void dfs(int, int)':
Ioi.cpp:88:13: warning: 'out' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |             if (w != out)
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4328 KB Output is correct
2 Correct 14 ms 4500 KB Output is correct
3 Correct 32 ms 4676 KB Output is correct
4 Correct 8 ms 4588 KB Output is correct
5 Correct 8 ms 4588 KB Output is correct
6 Correct 16 ms 4620 KB Output is correct
7 Correct 48 ms 4624 KB Output is correct
8 Correct 16 ms 4592 KB Output is correct
9 Correct 28 ms 4676 KB Output is correct
10 Correct 14 ms 4588 KB Output is correct
11 Correct 15 ms 4884 KB Output is correct
12 Correct 4 ms 4332 KB Output is correct
13 Correct 30 ms 4652 KB Output is correct
14 Correct 30 ms 4584 KB Output is correct
15 Correct 31 ms 4652 KB Output is correct
16 Correct 31 ms 4804 KB Output is correct
17 Correct 34 ms 4628 KB Output is correct
18 Correct 34 ms 4664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1322 ms 15700 KB Output is correct
2 Correct 1331 ms 15572 KB Output is correct
3 Correct 1327 ms 15444 KB Output is correct
4 Correct 1403 ms 13384 KB Output is correct
5 Correct 1210 ms 14540 KB Output is correct
6 Correct 1603 ms 14120 KB Output is correct
7 Correct 1617 ms 14032 KB Output is correct
8 Correct 1573 ms 14304 KB Output is correct
9 Correct 1476 ms 14192 KB Output is correct
10 Correct 528 ms 13140 KB Output is correct
11 Correct 533 ms 13344 KB Output is correct
12 Correct 1098 ms 12384 KB Output is correct
13 Correct 1100 ms 12452 KB Output is correct
14 Correct 1170 ms 12888 KB Output is correct
15 Correct 1225 ms 13296 KB Output is correct
16 Correct 1269 ms 13124 KB Output is correct
17 Correct 1392 ms 13196 KB Output is correct
18 Correct 1447 ms 13124 KB Output is correct
19 Correct 1502 ms 13528 KB Output is correct
20 Correct 604 ms 14644 KB Output is correct
21 Correct 587 ms 14180 KB Output is correct
22 Correct 1379 ms 13976 KB Output is correct
23 Correct 1383 ms 14120 KB Output is correct
24 Correct 1412 ms 14300 KB Output is correct
25 Correct 1383 ms 13984 KB Output is correct
26 Correct 1452 ms 14100 KB Output is correct
27 Correct 1507 ms 14144 KB Output is correct
28 Correct 1516 ms 14220 KB Output is correct
29 Correct 1331 ms 13240 KB Output is correct
30 Correct 1367 ms 13472 KB Output is correct
31 Correct 14 ms 4568 KB Output is correct
32 Correct 17 ms 4608 KB Output is correct
33 Correct 14 ms 4592 KB Output is correct
34 Correct 14 ms 4588 KB Output is correct
35 Correct 9 ms 4592 KB Output is correct
36 Correct 6 ms 4436 KB Output is correct
37 Correct 4 ms 4332 KB Output is correct
38 Correct 4 ms 4328 KB Output is correct
39 Correct 3 ms 4332 KB Output is correct
40 Correct 9 ms 4548 KB Output is correct
41 Correct 9 ms 4584 KB Output is correct
42 Correct 4 ms 4368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4588 KB Output is correct
2 Correct 5 ms 4584 KB Output is correct
3 Correct 6 ms 4608 KB Output is correct
4 Correct 89 ms 6152 KB Output is correct
5 Correct 88 ms 6060 KB Output is correct
6 Correct 98 ms 6096 KB Output is correct
7 Correct 90 ms 6068 KB Output is correct
8 Correct 96 ms 6076 KB Output is correct
9 Correct 518 ms 15580 KB Output is correct
10 Correct 566 ms 15788 KB Output is correct
11 Correct 523 ms 15772 KB Output is correct
12 Correct 4 ms 4400 KB Output is correct
13 Correct 4 ms 4336 KB Output is correct
14 Correct 3 ms 4336 KB Output is correct
15 Correct 4 ms 4336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1323 ms 15556 KB Output is correct
2 Correct 1318 ms 15840 KB Output is correct
3 Correct 1321 ms 15732 KB Output is correct
4 Correct 1355 ms 13492 KB Output is correct
5 Correct 1178 ms 15268 KB Output is correct
6 Correct 1496 ms 14412 KB Output is correct
7 Correct 1535 ms 14376 KB Output is correct
8 Correct 1571 ms 13960 KB Output is correct
9 Correct 1539 ms 14004 KB Output is correct
10 Correct 554 ms 13440 KB Output is correct
11 Correct 694 ms 13940 KB Output is correct
12 Correct 1087 ms 12904 KB Output is correct
13 Correct 1087 ms 12636 KB Output is correct
14 Correct 1157 ms 12956 KB Output is correct
15 Correct 1229 ms 13372 KB Output is correct
16 Correct 1271 ms 13372 KB Output is correct
17 Correct 1428 ms 13596 KB Output is correct
18 Correct 1431 ms 13260 KB Output is correct
19 Correct 1450 ms 13372 KB Output is correct
20 Correct 601 ms 14484 KB Output is correct
21 Correct 612 ms 14392 KB Output is correct
22 Correct 1396 ms 14504 KB Output is correct
23 Correct 1398 ms 14288 KB Output is correct
24 Correct 1370 ms 14308 KB Output is correct
25 Correct 1386 ms 14464 KB Output is correct
26 Correct 1396 ms 14372 KB Output is correct
27 Correct 1390 ms 14784 KB Output is correct
28 Correct 1377 ms 14204 KB Output is correct
29 Correct 1248 ms 13484 KB Output is correct
30 Correct 1315 ms 14048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1355 ms 15464 KB Output is correct
2 Correct 1338 ms 15760 KB Output is correct
3 Correct 1310 ms 15692 KB Output is correct
4 Correct 1385 ms 13564 KB Output is correct
5 Correct 1194 ms 15432 KB Output is correct
6 Correct 1552 ms 14492 KB Output is correct
7 Correct 1543 ms 14164 KB Output is correct
8 Correct 1484 ms 14304 KB Output is correct
9 Correct 1521 ms 14472 KB Output is correct
10 Correct 692 ms 13484 KB Output is correct
11 Correct 643 ms 13500 KB Output is correct
12 Correct 1105 ms 12500 KB Output is correct
13 Correct 1076 ms 12584 KB Output is correct
14 Correct 1160 ms 13068 KB Output is correct
15 Correct 1498 ms 13444 KB Output is correct
16 Correct 1267 ms 13436 KB Output is correct
17 Correct 1458 ms 13368 KB Output is correct
18 Correct 1435 ms 13372 KB Output is correct
19 Correct 1460 ms 13520 KB Output is correct
20 Correct 596 ms 14600 KB Output is correct
21 Correct 581 ms 14416 KB Output is correct
22 Correct 1399 ms 14312 KB Output is correct
23 Correct 1388 ms 14272 KB Output is correct
24 Correct 1392 ms 14148 KB Output is correct
25 Correct 1392 ms 14324 KB Output is correct
26 Correct 1388 ms 14104 KB Output is correct
27 Correct 1383 ms 14572 KB Output is correct
28 Correct 1402 ms 14616 KB Output is correct
29 Correct 1246 ms 13976 KB Output is correct
30 Correct 1328 ms 14056 KB Output is correct
31 Correct 14 ms 4592 KB Output is correct
32 Correct 16 ms 4600 KB Output is correct
33 Correct 16 ms 4596 KB Output is correct
34 Correct 14 ms 4592 KB Output is correct
35 Correct 8 ms 4544 KB Output is correct
36 Correct 6 ms 4336 KB Output is correct
37 Correct 4 ms 4472 KB Output is correct
38 Correct 4 ms 4336 KB Output is correct
39 Correct 4 ms 4408 KB Output is correct
40 Correct 8 ms 4472 KB Output is correct
41 Correct 8 ms 4588 KB Output is correct
42 Correct 4 ms 4344 KB Output is correct