답안 #228135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228135 2020-04-30T03:34:32 Z qkxwsm Amusement Park (JOI17_amusement_park) C++14
0 / 100
56 ms 9420 KB
#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

static const int MAXN = 10013;
static const int MAGIC = 60;

static int N, R;
static vi edge[MAXN];
static int dsu[MAXN];
static vi ord;
static vi nodes[MAXN];
static bool vis[MAXN], inside[MAXN];
static int parent[MAXN], label[MAXN];

static int get(int u)
{
    return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
static bool merge(int u, int v)
{
    u = get(u);
    v = get(v);
    if (u == v)
    {
        return false;
    }
    dsu[u] = v;
    return true;
}
static void gen()
{
    //generates all the labels for all the nodes.
    queue<int> q; q.push(0);
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        label[u] = SZ(nodes[0]);
        nodes[0].PB(u);
        vis[u] = true;
        if (SZ(nodes[0]) == MAGIC)
        {
            break;
        }
        for (int v : edge[u])
        {
            if (vis[v])
            {
                continue;
            }
            parent[v] = u;
            q.push(v);
        }
    }
    FOR(i, 1, SZ(nodes[0]))
    {
        nodes[nodes[0][i]] = nodes[0];
    }
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        vis[u] = true;
        for (int v : nodes[parent[u]])
        {
            inside[v] = true;
        }
        nodes[u] = nodes[parent[u]];
        FOR(i, 0, SZ(nodes[parent[u]]))
        {
            int v = nodes[parent[u]][i];
            if (v == parent[u]) continue;
            int c = 0;
            for (int x : edge[v])
            {
                if (inside[x]) c++;
            }
            if (c == 1)
            {
                label[u] = label[v];
                nodes[u][i] = u;
                break;
            }
        }
        for (int v : nodes[parent[u]])
        {
            inside[v] = false;
            //you just wanna find any leaf, except w
        }
        for (int v : edge[u])
        {
            if (vis[v])
            {
                continue;
            }
            parent[v] = u;
            q.push(v);
        }
    }
}

void Joi(int n, int m, int e1[], int e2[], ll val, int subtask)
{
    N = n;
    iota(dsu, dsu + N, 0);
    FOR(i, 0, m)
    {
        int u = e1[i], v = e2[i];
        if (merge(u, v))
        {
            edge[u].PB(v);
            edge[v].PB(u);
        }
    }
    gen();
    FOR(i, 0, N)
    {
        int x = label[i];
        MessageBoard(i, (val & (1ll << x)) ? 1 : 0);
    }
    //generate a tree for each node.
}
#include "Ioi.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

static const int MAXN = 10013;
static const int MAGIC = 60;

static int N, R, V = -1;
static vi edge[MAXN];
static int dsu[MAXN];
static ll ans;
static vi ord;
static vi nodes[MAXN];
static bool vis[MAXN], inside[MAXN];
static int parent[MAXN], label[MAXN];

static int get(int u)
{
    return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
static bool merge(int u, int v)
{
    u = get(u);
    v = get(v);
    if (u == v)
    {
        return false;
    }
    dsu[u] = v;
    return true;
}
static void gen()
{
    //generates all the labels for all the nodes.
    queue<int> q; q.push(0);
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        label[u] = SZ(nodes[0]);
        nodes[0].PB(u);
        vis[u] = true;
        if (SZ(nodes[0]) == MAGIC)
        {
            break;
        }
        for (int v : edge[u])
        {
            if (vis[v])
            {
                continue;
            }
            parent[v] = u;
            q.push(v);
        }
    }
    FOR(i, 1, SZ(nodes[0]))
    {
        nodes[nodes[0][i]] = nodes[0];
    }
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        vis[u] = true;
        for (int v : nodes[parent[u]])
        {
            inside[v] = true;
        }
        nodes[u] = nodes[parent[u]];
        FOR(i, 0, SZ(nodes[parent[u]]))
        {
            int v = nodes[parent[u]][i];
            if (v == parent[u]) continue;
            int c = 0;
            for (int x : edge[v])
            {
                if (inside[x]) c++;
            }
            if (c == 1)
            {
                label[u] = label[v];
                nodes[u][i] = u;
                break;
            }
        }
        for (int v : nodes[parent[u]])
        {
            inside[v] = false;
            //you just wanna find any leaf, except w
        }
        for (int v : edge[u])
        {
            if (vis[v])
            {
                continue;
            }
            parent[v] = u;
            q.push(v);
        }
    }
}
void dfs(int u, int p, int va)
{
    int x = label[u];
    if (va)
    {
        ans += (1ll << x);
    }
    for (int v : edge[u])
    {
        if (v == p || !inside[v])
        {
            continue;
        }
        int vv = Move(v);
        dfs(v, u, vv);
        Move(u);
    }
}

ll Ioi(int n, int m, int e1[], int e2[], int st, int va, int subtask)
{
    N = n;
    iota(dsu, dsu + N, 0);
    FOR(i, 0, m)
    {
        int u = e1[i], v = e2[i];
        if (merge(u, v))
        {
            edge[u].PB(v);
            edge[v].PB(u);
            // cerr << "edge " << u << ' ' << v << endl;
        }
    }
    gen();
    FOR(i, 0, N)
    {
        inside[i] = false;
    }
    for (int u : nodes[st])
    {
        inside[u] = true;
    }
    dfs(st, N, va);
    cerr << "Return " << ans << endl;
    return ans;
}

Compilation message

Joi.cpp:41:15: warning: 'R' defined but not used [-Wunused-variable]
 static int N, R;
               ^

Ioi.cpp:41:18: warning: 'V' defined but not used [-Wunused-variable]
 static int N, R, V = -1;
                  ^
Ioi.cpp:41:15: warning: 'R' defined but not used [-Wunused-variable]
 static int N, R, V = -1;
               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1888 KB Output is correct
2 Correct 10 ms 1928 KB Output is correct
3 Correct 10 ms 1948 KB Output is correct
4 Incorrect 10 ms 2040 KB Wrong Answer [7]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 9288 KB Output is correct
2 Correct 55 ms 9420 KB Output is correct
3 Correct 56 ms 9100 KB Output is correct
4 Correct 40 ms 8524 KB Output is correct
5 Incorrect 31 ms 6048 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2028 KB Output is correct
2 Correct 10 ms 1916 KB Output is correct
3 Incorrect 10 ms 2020 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 9404 KB Output is correct
2 Correct 55 ms 9364 KB Output is correct
3 Correct 53 ms 9388 KB Output is correct
4 Correct 41 ms 8652 KB Output is correct
5 Incorrect 27 ms 4544 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 4304 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -