Submission #204157

# Submission time Handle Problem Language Result Execution time Memory
204157 2020-02-24T16:55:26 Z cheetose Meetings (JOI19_meetings) C++17
100 / 100
847 ms 1016 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i, a, b, c) for (int(i) = (a); (i) <= (b); (i) += (c))
#define fdn(i, a, b, c) for (int(i) = (a); (i) >= (b); (i) -= (c))
#define MEM0(a) memset((a), 0, sizeof(a));
#define MEM_1(a) memset((a), -1, sizeof(a));
#define ALL(a) a.begin(), a.end()
#define SYNC                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {
    ll ret = 1;
    for (; b; b >>= 1, a = (a * a) % MMM)
        if (b & 1)
            ret = (ret * a) % MMM;
    return ret;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
    if (a == 0 || b == 0)
        return a + b;
    return a * (b / gcd(a, b));
}
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 }, dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int ddx[] = { -1, -2, 1, -2, 2, -1, 2, 1 }, ddy[] = { -2, -1, -2, 1, -1, 2, 1, 2 };

#include "meetings.h"
#define kill kool
Vi v[2005];
void discon(int x, int y) {
    for (int &z : v[x]) {
        if (z == y) {
            z = v[x].back();
            v[x].back() = y;
            break;
        }
    }
    for (int &z : v[y]) {
        if (z == x) {
            z = v[y].back();
            v[y].back() = x;
            break;
        }
    }
    v[x].pop_back();
    v[y].pop_back();
}
void con(int x, int y) {
    v[x].pb(y);
    v[y].pb(x);
}

bool chk[2005], kill[2005];
int sz[2005];
int getSz(int N, int pp) {
    sz[N] = 1;
    for (int next : v[N]) {
        if (next == pp || kill[next])
            continue;
        sz[N] += getSz(next, N);
    }
    return sz[N];
}
int get_centroid(int N, int pp, int cap) {
    for (int next : v[N]) {
        if (kill[next] || next == pp)
            continue;
        if (sz[next] > cap)
            return get_centroid(next, N, cap);
    }
    return N;
}
void Solve(int N) {
    chk[0] = chk[1] = chk[2] = 1;
    int w = Query(0, 1, 2);
    if (w > 2) {
        chk[w] = 1;
        con(0, w);
        con(1, w);
        con(2, w);
    } else {
        fup(i, 0, 2, 1) if (w != i) con(i, w);
    }
    fup(i, 3, N - 1, 1) {
        MEM0(kill);
        if (chk[i])
            continue;
        chk[i] = 1;
        int pr = 0;
        while (1) {
            int cap = getSz(pr, -1);
            int R = get_centroid(pr, -1, cap / 2);
            getSz(R, -1);
            sort(ALL(v[R]), [&](int a, int b) { return sz[a] > sz[b]; });
            kill[R] = 1;
            int t = -1;
            fup(j, 1, (int)v[R].size() - 1, 2) {
                int a = v[R][j - 1], b = v[R][j];
                int x = Query(a, i, b);
                if (x == i) {
                    int T = Query(R, i, a);
                    if (T == i) {
                        discon(R, a);
                        con(R, i);
                        con(i, a);
                    } else {
                        discon(R, b);
                        con(R, i);
                        con(i, b);
                    }
                    goto FIN;
                } else if (x != R) {
                    t = x;
                    break;
                }
            }
            if (t == -1 && v[R].size() & 1) {
                int x = Query(R, i, v[R].back());
                if (x == i) {
                    int B = v[R].back();
                    discon(R, B);
                    con(R, i);
                    con(i, B);
                    goto FIN;
                } else if (x != R)
                    t = x;
            }
            if (t == -1) {
                con(R, i);
                goto FIN;
            } else {
                pr = t;
            }
        }
    FIN:;
    }
    fup(i, 0, N - 1, 1) {
        for (int x : v[i]) {
            if (x > i)
                Bridge(i, x);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 13 ms 504 KB Output is correct
28 Correct 11 ms 376 KB Output is correct
29 Correct 12 ms 376 KB Output is correct
30 Correct 10 ms 376 KB Output is correct
31 Correct 12 ms 508 KB Output is correct
32 Correct 11 ms 376 KB Output is correct
33 Correct 14 ms 376 KB Output is correct
34 Correct 16 ms 376 KB Output is correct
35 Correct 14 ms 504 KB Output is correct
36 Correct 10 ms 376 KB Output is correct
37 Correct 14 ms 504 KB Output is correct
38 Correct 14 ms 508 KB Output is correct
39 Correct 14 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 593 ms 760 KB Output is correct
2 Correct 592 ms 636 KB Output is correct
3 Correct 590 ms 888 KB Output is correct
4 Correct 550 ms 760 KB Output is correct
5 Correct 486 ms 632 KB Output is correct
6 Correct 470 ms 760 KB Output is correct
7 Correct 495 ms 760 KB Output is correct
8 Correct 532 ms 632 KB Output is correct
9 Correct 504 ms 764 KB Output is correct
10 Correct 492 ms 764 KB Output is correct
11 Correct 539 ms 764 KB Output is correct
12 Correct 624 ms 784 KB Output is correct
13 Correct 573 ms 760 KB Output is correct
14 Correct 424 ms 760 KB Output is correct
15 Correct 508 ms 888 KB Output is correct
16 Correct 482 ms 760 KB Output is correct
17 Correct 456 ms 760 KB Output is correct
18 Correct 433 ms 760 KB Output is correct
19 Correct 471 ms 768 KB Output is correct
20 Correct 521 ms 772 KB Output is correct
21 Correct 563 ms 760 KB Output is correct
22 Correct 544 ms 1016 KB Output is correct
23 Correct 556 ms 760 KB Output is correct
24 Correct 614 ms 764 KB Output is correct
25 Correct 584 ms 764 KB Output is correct
26 Correct 583 ms 760 KB Output is correct
27 Correct 585 ms 760 KB Output is correct
28 Correct 599 ms 760 KB Output is correct
29 Correct 508 ms 760 KB Output is correct
30 Correct 504 ms 760 KB Output is correct
31 Correct 598 ms 760 KB Output is correct
32 Correct 847 ms 764 KB Output is correct
33 Correct 679 ms 888 KB Output is correct
34 Correct 11 ms 376 KB Output is correct
35 Correct 12 ms 504 KB Output is correct
36 Correct 13 ms 504 KB Output is correct
37 Correct 11 ms 504 KB Output is correct
38 Correct 11 ms 504 KB Output is correct
39 Correct 12 ms 376 KB Output is correct
40 Correct 14 ms 504 KB Output is correct
41 Correct 16 ms 376 KB Output is correct
42 Correct 14 ms 504 KB Output is correct
43 Correct 11 ms 376 KB Output is correct
44 Correct 14 ms 376 KB Output is correct
45 Correct 14 ms 504 KB Output is correct
46 Correct 14 ms 504 KB Output is correct
47 Correct 5 ms 504 KB Output is correct
48 Correct 5 ms 376 KB Output is correct
49 Correct 5 ms 376 KB Output is correct
50 Correct 5 ms 376 KB Output is correct
51 Correct 5 ms 376 KB Output is correct
52 Correct 5 ms 504 KB Output is correct
53 Correct 5 ms 376 KB Output is correct
54 Correct 5 ms 376 KB Output is correct
55 Correct 5 ms 376 KB Output is correct
56 Correct 5 ms 376 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 5 ms 376 KB Output is correct
59 Correct 5 ms 376 KB Output is correct
60 Correct 5 ms 380 KB Output is correct
61 Correct 5 ms 376 KB Output is correct
62 Correct 5 ms 376 KB Output is correct
63 Correct 5 ms 376 KB Output is correct
64 Correct 5 ms 376 KB Output is correct
65 Correct 5 ms 376 KB Output is correct
66 Correct 5 ms 380 KB Output is correct
67 Correct 5 ms 376 KB Output is correct
68 Correct 4 ms 376 KB Output is correct
69 Correct 5 ms 380 KB Output is correct
70 Correct 5 ms 504 KB Output is correct
71 Correct 5 ms 376 KB Output is correct
72 Correct 5 ms 376 KB Output is correct