Submission #470281

# Submission time Handle Problem Language Result Execution time Memory
470281 2021-09-03T11:21:12 Z luciocf Amusement Park (JOI17_amusement_park) C++14
18 / 100
1624 ms 15780 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)
{
    for (auto v: grafo[u])
    {
        if (v == p) continue;

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

        if (!ok) continue;

        on[bit[v]] = Move(v);
        get(v, u);
        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);

    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)
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4332 KB Output is correct
2 Correct 15 ms 4596 KB Output is correct
3 Correct 31 ms 4588 KB Output is correct
4 Correct 8 ms 4592 KB Output is correct
5 Correct 8 ms 4588 KB Output is correct
6 Correct 18 ms 4656 KB Output is correct
7 Correct 35 ms 4628 KB Output is correct
8 Correct 14 ms 4608 KB Output is correct
9 Correct 28 ms 4616 KB Output is correct
10 Correct 14 ms 4528 KB Output is correct
11 Correct 15 ms 4920 KB Output is correct
12 Correct 4 ms 4332 KB Output is correct
13 Correct 34 ms 4628 KB Output is correct
14 Correct 31 ms 4580 KB Output is correct
15 Correct 33 ms 4596 KB Output is correct
16 Correct 31 ms 4600 KB Output is correct
17 Correct 34 ms 4632 KB Output is correct
18 Correct 33 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1329 ms 15460 KB Output is correct
2 Correct 1392 ms 15780 KB Output is correct
3 Correct 1351 ms 15760 KB Output is correct
4 Correct 1394 ms 13344 KB Output is correct
5 Correct 1196 ms 14772 KB Output is correct
6 Correct 1550 ms 14084 KB Output is correct
7 Correct 1624 ms 14228 KB Output is correct
8 Correct 1552 ms 14528 KB Output is correct
9 Correct 1510 ms 14352 KB Output is correct
10 Correct 497 ms 13376 KB Output is correct
11 Correct 521 ms 13496 KB Output is correct
12 Correct 1097 ms 12560 KB Output is correct
13 Correct 1081 ms 12500 KB Output is correct
14 Correct 1157 ms 12996 KB Output is correct
15 Correct 1310 ms 13332 KB Output is correct
16 Correct 1281 ms 13396 KB Output is correct
17 Correct 1378 ms 13372 KB Output is correct
18 Correct 1379 ms 13528 KB Output is correct
19 Correct 1447 ms 13464 KB Output is correct
20 Correct 569 ms 14624 KB Output is correct
21 Correct 563 ms 14596 KB Output is correct
22 Correct 1420 ms 13964 KB Output is correct
23 Correct 1377 ms 14484 KB Output is correct
24 Correct 1440 ms 14036 KB Output is correct
25 Correct 1359 ms 14332 KB Output is correct
26 Correct 1387 ms 14324 KB Output is correct
27 Correct 1439 ms 14364 KB Output is correct
28 Correct 1376 ms 14524 KB Output is correct
29 Correct 1265 ms 13504 KB Output is correct
30 Correct 1327 ms 13824 KB Output is correct
31 Correct 15 ms 4592 KB Output is correct
32 Correct 16 ms 4536 KB Output is correct
33 Correct 13 ms 4652 KB Output is correct
34 Correct 16 ms 4592 KB Output is correct
35 Correct 9 ms 4596 KB Output is correct
36 Correct 6 ms 4344 KB Output is correct
37 Correct 4 ms 4336 KB Output is correct
38 Correct 3 ms 4336 KB Output is correct
39 Correct 3 ms 4332 KB Output is correct
40 Correct 7 ms 4596 KB Output is correct
41 Correct 8 ms 4592 KB Output is correct
42 Correct 4 ms 4468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4592 KB Output is correct
2 Correct 5 ms 4592 KB Output is correct
3 Correct 6 ms 4576 KB Output is correct
4 Correct 81 ms 6080 KB Output is correct
5 Incorrect 86 ms 6128 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1326 ms 15420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1315 ms 15492 KB Output isn't correct
2 Halted 0 ms 0 KB -