Submission #110000

# Submission time Handle Problem Language Result Execution time Memory
110000 2019-05-08T15:14:36 Z popovicirobert Amusement Park (JOI17_amusement_park) C++14
100 / 100
89 ms 10460 KB
#include "Joi.h"
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct DSU {

    vector <int> par;
    int n;

    inline void init(int _n) {
        n = _n;
        par.resize(n + 1, -1);
    }

    int root(int x) {
        if(par[x] == -1) return x;
        return par[x] = root(par[x]);
    }

    inline void join(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] = y;
        }
    }

};

static vector < vector <int> > g;

static void make_mst(int n, int m, int A[], int B[]) {

    DSU dsu; dsu.init(n);
    g.resize(n);

    for(int i = 0; i < m; i++) {
        if(dsu.root(A[i]) != dsu.root(B[i])) {
            dsu.join(A[i], B[i]);
            g[A[i]].push_back(B[i]);
            g[B[i]].push_back(A[i]);
        }
    }

}

static vector < vector <int> > group;
static vector <int> bit;

static void dfs(int nod, int par, int &cur) {

    if(cur == 60) {
        return ;
    }

    bit[nod] = cur++;

    for(auto it : g[nod]) {
        if(it != par) {
            dfs(it, nod, cur);
        }
    }

}

static vector <int> vis;
static int now;

static void dfs1(int nod, int par) {

    if(bit[nod] == -1) {
        now++;
        for(auto it : group[par]) {
            vis[it] = now;
        }

        for(auto it : group[par]) {

            int cnt = 0;
            for(auto son : g[it]) {
                if(vis[son] == now) {
                    cnt++;
                }
            }

            if(cnt == 1 && it != par) {
                bit[nod] = bit[it];
                group[nod].push_back(nod);

                for(auto son : group[par]) {
                    if(son != it) {
                        group[nod].push_back(son);
                    }
                }

                break;
            }
        }
    }

    for(auto it : g[nod]) {
        if(it != par) {
            dfs1(it, nod);
        }
    }

}

void Joi(int N, int M, int A[], int B[], long long X, int T) {

    make_mst(N, M, A, B);

    bit.resize(N, -1);

    int cur = 0;
    dfs(0, -1, cur);

    group.resize(N);

    int i;
    for(i = 0; i < N; i++) {
        if(bit[i] > -1) {
            group[0].push_back(i);
        }
    }
    for(i = 1; i < N; i++) {
        if(bit[i] > -1) {
            group[i] = group[0];
        }
    }

    vis.resize(N);
    dfs1(0, -1);

    vector <bool> sol(N);
    for(i = 0; i < N; i++) {
        sol[i] = ((X & (1LL << bit[i])) > 0);
    }

    for(i = 0; i < N; i++) {
        MessageBoard(i, sol[i]);
    }

}
#include "Ioi.h"
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct DSU {

    vector <int> par;
    int n;

    inline void init(int _n) {
        n = _n;
        par.resize(n + 1, -1);
    }

    int root(int x) {
        if(par[x] == -1) return x;
        return par[x] = root(par[x]);
    }

    inline void join(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] = y;
        }
    }

};

static vector < vector <int> > g;

static void make_mst(int n, int m, int A[], int B[]) {

    DSU dsu; dsu.init(n);
    g.resize(n);

    for(int i = 0; i < m; i++) {
        if(dsu.root(A[i]) != dsu.root(B[i])) {
            dsu.join(A[i], B[i]);
            g[A[i]].push_back(B[i]);
            g[B[i]].push_back(A[i]);
        }
    }

}

static vector < vector <int> > group;
static vector <int> bit;

static void dfs(int nod, int par, int &cur) {

    if(cur == 60) {
        return ;
    }

    bit[nod] = cur++;

    for(auto it : g[nod]) {
        if(it != par) {
            dfs(it, nod, cur);
        }
    }

}

static vector <int> vis;
static int now;

static void dfs1(int nod, int par) {

    if(bit[nod] == -1) {
        now++;
        for(auto it : group[par]) {
            vis[it] = now;
        }

        for(auto it : group[par]) {

            int cnt = 0;
            for(auto son : g[it]) {
                if(vis[son] == now) {
                    cnt++;
                }
            }

            if(cnt == 1 && it != par) {
                bit[nod] = bit[it];
                group[nod].push_back(nod);

                for(auto son : group[par]) {
                    if(son != it) {
                        group[nod].push_back(son);
                    }
                }

                break;
            }
        }
    }

    for(auto it : g[nod]) {
        if(it != par) {
            dfs1(it, nod);
        }
    }

}


void solve(int nod, ll &ans) {

    vis[nod] = 0;

    for(auto it : g[nod]) {
        if(vis[it] == 1) {
            ans += Move(it) * (1LL << bit[it]);

            solve(it, ans);

            Move(nod);
        }
    }

}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {

    make_mst(N, M, A, B);

    bit.resize(N, -1);

    int cur = 0;
    dfs(0, -1, cur);

    group.resize(N);

    int i;
    for(i = 0; i < N; i++) {
        if(bit[i] > -1) {
            group[0].push_back(i);
        }
    }

    for(i = 1; i < N; i++) {
        if(bit[i] > -1) {
            group[i] = group[0];
        }
    }

    vis.resize(N);
    dfs1(0, -1);

    fill(vis.begin(), vis.end(), 0);
    for(auto it : group[P]) {
        vis[it] = 1;
    }

    ll ans = V * (1LL << bit[P]);
    solve(P, ans);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 776 KB Output is correct
2 Correct 6 ms 904 KB Output is correct
3 Correct 6 ms 904 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 6 ms 1156 KB Output is correct
8 Correct 6 ms 900 KB Output is correct
9 Correct 5 ms 900 KB Output is correct
10 Correct 6 ms 904 KB Output is correct
11 Correct 11 ms 1072 KB Output is correct
12 Correct 5 ms 776 KB Output is correct
13 Correct 6 ms 1164 KB Output is correct
14 Correct 6 ms 1132 KB Output is correct
15 Correct 9 ms 1164 KB Output is correct
16 Correct 6 ms 900 KB Output is correct
17 Correct 5 ms 1272 KB Output is correct
18 Correct 4 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 9532 KB Output is correct
2 Correct 63 ms 9528 KB Output is correct
3 Correct 89 ms 9564 KB Output is correct
4 Correct 41 ms 8792 KB Output is correct
5 Correct 49 ms 9400 KB Output is correct
6 Correct 51 ms 9288 KB Output is correct
7 Correct 56 ms 9324 KB Output is correct
8 Correct 53 ms 9552 KB Output is correct
9 Correct 66 ms 9456 KB Output is correct
10 Correct 42 ms 8864 KB Output is correct
11 Correct 41 ms 8776 KB Output is correct
12 Correct 38 ms 8036 KB Output is correct
13 Correct 43 ms 7972 KB Output is correct
14 Correct 48 ms 8268 KB Output is correct
15 Correct 45 ms 8724 KB Output is correct
16 Correct 57 ms 8764 KB Output is correct
17 Correct 51 ms 8888 KB Output is correct
18 Correct 48 ms 8664 KB Output is correct
19 Correct 40 ms 8704 KB Output is correct
20 Correct 48 ms 9544 KB Output is correct
21 Correct 47 ms 9296 KB Output is correct
22 Correct 71 ms 9072 KB Output is correct
23 Correct 53 ms 9444 KB Output is correct
24 Correct 56 ms 9304 KB Output is correct
25 Correct 62 ms 9304 KB Output is correct
26 Correct 57 ms 9424 KB Output is correct
27 Correct 51 ms 9472 KB Output is correct
28 Correct 55 ms 9572 KB Output is correct
29 Correct 60 ms 8672 KB Output is correct
30 Correct 48 ms 8764 KB Output is correct
31 Correct 6 ms 776 KB Output is correct
32 Correct 6 ms 1032 KB Output is correct
33 Correct 6 ms 1048 KB Output is correct
34 Correct 5 ms 904 KB Output is correct
35 Correct 6 ms 988 KB Output is correct
36 Correct 5 ms 960 KB Output is correct
37 Correct 4 ms 836 KB Output is correct
38 Correct 4 ms 904 KB Output is correct
39 Correct 4 ms 904 KB Output is correct
40 Correct 4 ms 952 KB Output is correct
41 Correct 4 ms 776 KB Output is correct
42 Correct 4 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 776 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 11 ms 2332 KB Output is correct
5 Correct 11 ms 2332 KB Output is correct
6 Correct 11 ms 2332 KB Output is correct
7 Correct 11 ms 2340 KB Output is correct
8 Correct 14 ms 2460 KB Output is correct
9 Correct 43 ms 10296 KB Output is correct
10 Correct 44 ms 10460 KB Output is correct
11 Correct 40 ms 10460 KB Output is correct
12 Correct 5 ms 904 KB Output is correct
13 Correct 6 ms 960 KB Output is correct
14 Correct 6 ms 768 KB Output is correct
15 Correct 4 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 9196 KB Output is correct
2 Correct 64 ms 9552 KB Output is correct
3 Correct 54 ms 9556 KB Output is correct
4 Correct 44 ms 8756 KB Output is correct
5 Correct 65 ms 10064 KB Output is correct
6 Correct 50 ms 9572 KB Output is correct
7 Correct 48 ms 9472 KB Output is correct
8 Correct 56 ms 9324 KB Output is correct
9 Correct 56 ms 9328 KB Output is correct
10 Correct 39 ms 8688 KB Output is correct
11 Correct 48 ms 8704 KB Output is correct
12 Correct 52 ms 8144 KB Output is correct
13 Correct 48 ms 8176 KB Output is correct
14 Correct 55 ms 8412 KB Output is correct
15 Correct 46 ms 8764 KB Output is correct
16 Correct 47 ms 8760 KB Output is correct
17 Correct 52 ms 8944 KB Output is correct
18 Correct 49 ms 8944 KB Output is correct
19 Correct 53 ms 8808 KB Output is correct
20 Correct 41 ms 9568 KB Output is correct
21 Correct 39 ms 9528 KB Output is correct
22 Correct 56 ms 9456 KB Output is correct
23 Correct 62 ms 9320 KB Output is correct
24 Correct 56 ms 9312 KB Output is correct
25 Correct 65 ms 9468 KB Output is correct
26 Correct 54 ms 9580 KB Output is correct
27 Correct 52 ms 9584 KB Output is correct
28 Correct 55 ms 9272 KB Output is correct
29 Correct 49 ms 8540 KB Output is correct
30 Correct 48 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 9132 KB Output is correct
2 Correct 69 ms 9448 KB Output is correct
3 Correct 61 ms 9508 KB Output is correct
4 Correct 48 ms 8816 KB Output is correct
5 Correct 57 ms 10344 KB Output is correct
6 Correct 52 ms 9216 KB Output is correct
7 Correct 52 ms 9200 KB Output is correct
8 Correct 54 ms 9464 KB Output is correct
9 Correct 66 ms 9320 KB Output is correct
10 Correct 39 ms 8828 KB Output is correct
11 Correct 39 ms 8692 KB Output is correct
12 Correct 43 ms 8192 KB Output is correct
13 Correct 56 ms 8032 KB Output is correct
14 Correct 45 ms 8292 KB Output is correct
15 Correct 70 ms 8784 KB Output is correct
16 Correct 56 ms 8760 KB Output is correct
17 Correct 53 ms 8824 KB Output is correct
18 Correct 52 ms 8832 KB Output is correct
19 Correct 52 ms 8824 KB Output is correct
20 Correct 45 ms 9600 KB Output is correct
21 Correct 52 ms 9612 KB Output is correct
22 Correct 56 ms 9588 KB Output is correct
23 Correct 49 ms 9216 KB Output is correct
24 Correct 62 ms 9512 KB Output is correct
25 Correct 52 ms 9352 KB Output is correct
26 Correct 65 ms 9348 KB Output is correct
27 Correct 48 ms 9624 KB Output is correct
28 Correct 74 ms 9652 KB Output is correct
29 Correct 54 ms 8780 KB Output is correct
30 Correct 52 ms 9084 KB Output is correct
31 Correct 6 ms 896 KB Output is correct
32 Correct 5 ms 904 KB Output is correct
33 Correct 5 ms 1140 KB Output is correct
34 Correct 4 ms 768 KB Output is correct
35 Correct 5 ms 904 KB Output is correct
36 Correct 5 ms 776 KB Output is correct
37 Correct 4 ms 768 KB Output is correct
38 Correct 4 ms 768 KB Output is correct
39 Correct 5 ms 964 KB Output is correct
40 Correct 5 ms 856 KB Output is correct
41 Correct 5 ms 904 KB Output is correct
42 Correct 5 ms 896 KB Output is correct