답안 #349528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349528 2021-01-17T18:35:05 Z parsabahrami 자매 도시 (APIO20_swap) C++17
53 / 100
356 ms 25588 KB
#include "swap.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O2")

using namespace std;

typedef long long int ll;
typedef pair<int, int > pii;

#define SZ(x)               (int) x.size()
#define F                   first
#define S                   second

const int N = 2e5 + 10;
int P[19][N], H[N], C[N], rt[N], D[N], M[N], tim;

int Find(int v) {
    return !rt[v] ? v : rt[v] = Find(rt[v]);
}

void Union(int u, int v, int w) {
    u = Find(u), v = Find(v);
    if (u == v) {
        ++tim;
        P[0][u] = rt[u] = P[0][tim] = tim;
        C[u] = w; M[tim] = 1;
    } else {
        ++tim;
        rt[u] = rt[v] = P[0][u] = P[0][v] = P[0][tim] = tim;
        C[u] = C[v] = w;
        M[tim] = M[u] | M[v];
    }
}

void init(int n, int m,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    tim = n - 1; vector<pair<int, pii>> E;
    for (int i = 0; i < m; i++) {
        E.push_back({W[i], {U[i], V[i]}});
    }
    sort(E.begin(), E.end());
    for (auto e : E) {
        int w = e.F, u = e.S.F, v = e.S.S;
        D[u]++, D[v]++;
        Union(u, v, w);
        if (D[u] > 2 || D[v] > 2) M[Find(u)] = 1;
    }
    for (int i = 1; i < 19; i++) for (int j = 0; j <= tim; j++) P[i][j] = P[i - 1][P[i - 1][j]];
    for (int i = tim - 1; i >= 0; i--) H[i] = H[P[0][i]] + 1;
}

int getMinimumFuelCapacity(int u, int v) {
    if (H[u] < H[v]) swap(u, v);
    for (int i = H[u] - H[v]; i; i -= i & -i) u = P[__builtin_ctz(i)][u];
    for (int i = 18; ~i; i--) {
        if (P[i][u] != P[i][v] || !M[P[i][v]]) {
            u = P[i][u], v = P[i][v];
        }
    }
    if (P[0][u] != P[0][v]) return -1;
    if (!M[P[0][u]]) return -1;
    return C[u];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 62 ms 21344 KB Output is correct
11 Correct 66 ms 20960 KB Output is correct
12 Correct 65 ms 22112 KB Output is correct
13 Correct 64 ms 23648 KB Output is correct
14 Correct 60 ms 17760 KB Output is correct
15 Correct 155 ms 23136 KB Output is correct
16 Correct 153 ms 22496 KB Output is correct
17 Correct 155 ms 23648 KB Output is correct
18 Correct 235 ms 25204 KB Output is correct
19 Correct 87 ms 7404 KB Output is correct
20 Correct 229 ms 23264 KB Output is correct
21 Correct 241 ms 22832 KB Output is correct
22 Correct 245 ms 24108 KB Output is correct
23 Correct 356 ms 25588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 345 ms 22948 KB Output is correct
4 Correct 345 ms 23852 KB Output is correct
5 Correct 352 ms 23432 KB Output is correct
6 Correct 344 ms 23728 KB Output is correct
7 Correct 346 ms 23644 KB Output is correct
8 Correct 338 ms 22716 KB Output is correct
9 Correct 342 ms 23520 KB Output is correct
10 Correct 339 ms 22612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 1 ms 748 KB Output is correct
24 Correct 2 ms 876 KB Output is correct
25 Correct 2 ms 876 KB Output is correct
26 Correct 2 ms 876 KB Output is correct
27 Correct 1 ms 748 KB Output is correct
28 Correct 2 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 52 ms 17632 KB Output is correct
11 Correct 62 ms 21344 KB Output is correct
12 Correct 66 ms 20960 KB Output is correct
13 Correct 65 ms 22112 KB Output is correct
14 Correct 64 ms 23648 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 1 ms 748 KB Output is correct
23 Correct 1 ms 748 KB Output is correct
24 Correct 9 ms 3628 KB Output is correct
25 Correct 63 ms 22112 KB Output is correct
26 Correct 67 ms 22240 KB Output is correct
27 Correct 62 ms 22112 KB Output is correct
28 Correct 62 ms 21856 KB Output is correct
29 Correct 62 ms 21728 KB Output is correct
30 Correct 60 ms 20192 KB Output is correct
31 Correct 66 ms 22112 KB Output is correct
32 Correct 62 ms 22112 KB Output is correct
33 Correct 60 ms 22112 KB Output is correct
34 Correct 67 ms 22112 KB Output is correct
35 Correct 1 ms 620 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 1 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 1 ms 748 KB Output is correct
40 Correct 2 ms 876 KB Output is correct
41 Correct 2 ms 876 KB Output is correct
42 Correct 2 ms 876 KB Output is correct
43 Correct 1 ms 748 KB Output is correct
44 Correct 2 ms 876 KB Output is correct
45 Runtime error 106 ms 17756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 62 ms 21344 KB Output is correct
11 Correct 66 ms 20960 KB Output is correct
12 Correct 65 ms 22112 KB Output is correct
13 Correct 64 ms 23648 KB Output is correct
14 Correct 60 ms 17760 KB Output is correct
15 Correct 155 ms 23136 KB Output is correct
16 Correct 153 ms 22496 KB Output is correct
17 Correct 155 ms 23648 KB Output is correct
18 Correct 235 ms 25204 KB Output is correct
19 Correct 345 ms 22948 KB Output is correct
20 Correct 345 ms 23852 KB Output is correct
21 Correct 352 ms 23432 KB Output is correct
22 Correct 344 ms 23728 KB Output is correct
23 Correct 346 ms 23644 KB Output is correct
24 Correct 338 ms 22716 KB Output is correct
25 Correct 342 ms 23520 KB Output is correct
26 Correct 339 ms 22612 KB Output is correct
27 Correct 1 ms 748 KB Output is correct
28 Correct 1 ms 748 KB Output is correct
29 Correct 1 ms 620 KB Output is correct
30 Correct 2 ms 620 KB Output is correct
31 Correct 1 ms 620 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
36 Correct 9 ms 3628 KB Output is correct
37 Correct 63 ms 22112 KB Output is correct
38 Correct 67 ms 22240 KB Output is correct
39 Correct 62 ms 22112 KB Output is correct
40 Correct 62 ms 21856 KB Output is correct
41 Correct 62 ms 21728 KB Output is correct
42 Correct 60 ms 20192 KB Output is correct
43 Correct 66 ms 22112 KB Output is correct
44 Correct 62 ms 22112 KB Output is correct
45 Correct 60 ms 22112 KB Output is correct
46 Correct 67 ms 22112 KB Output is correct
47 Correct 19 ms 3608 KB Output is correct
48 Correct 237 ms 23648 KB Output is correct
49 Correct 235 ms 23648 KB Output is correct
50 Correct 238 ms 23648 KB Output is correct
51 Correct 233 ms 23648 KB Output is correct
52 Correct 227 ms 22368 KB Output is correct
53 Correct 210 ms 17604 KB Output is correct
54 Correct 245 ms 23980 KB Output is correct
55 Correct 240 ms 23648 KB Output is correct
56 Correct 347 ms 23904 KB Output is correct
57 Correct 245 ms 23980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 748 KB Output is correct
10 Correct 52 ms 17632 KB Output is correct
11 Correct 62 ms 21344 KB Output is correct
12 Correct 66 ms 20960 KB Output is correct
13 Correct 65 ms 22112 KB Output is correct
14 Correct 64 ms 23648 KB Output is correct
15 Correct 60 ms 17760 KB Output is correct
16 Correct 155 ms 23136 KB Output is correct
17 Correct 153 ms 22496 KB Output is correct
18 Correct 155 ms 23648 KB Output is correct
19 Correct 235 ms 25204 KB Output is correct
20 Correct 345 ms 22948 KB Output is correct
21 Correct 345 ms 23852 KB Output is correct
22 Correct 352 ms 23432 KB Output is correct
23 Correct 344 ms 23728 KB Output is correct
24 Correct 346 ms 23644 KB Output is correct
25 Correct 338 ms 22716 KB Output is correct
26 Correct 342 ms 23520 KB Output is correct
27 Correct 339 ms 22612 KB Output is correct
28 Correct 1 ms 748 KB Output is correct
29 Correct 1 ms 748 KB Output is correct
30 Correct 1 ms 620 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
36 Correct 1 ms 748 KB Output is correct
37 Correct 9 ms 3628 KB Output is correct
38 Correct 63 ms 22112 KB Output is correct
39 Correct 67 ms 22240 KB Output is correct
40 Correct 62 ms 22112 KB Output is correct
41 Correct 62 ms 21856 KB Output is correct
42 Correct 62 ms 21728 KB Output is correct
43 Correct 60 ms 20192 KB Output is correct
44 Correct 66 ms 22112 KB Output is correct
45 Correct 62 ms 22112 KB Output is correct
46 Correct 60 ms 22112 KB Output is correct
47 Correct 67 ms 22112 KB Output is correct
48 Correct 19 ms 3608 KB Output is correct
49 Correct 237 ms 23648 KB Output is correct
50 Correct 235 ms 23648 KB Output is correct
51 Correct 238 ms 23648 KB Output is correct
52 Correct 233 ms 23648 KB Output is correct
53 Correct 227 ms 22368 KB Output is correct
54 Correct 210 ms 17604 KB Output is correct
55 Correct 245 ms 23980 KB Output is correct
56 Correct 240 ms 23648 KB Output is correct
57 Correct 347 ms 23904 KB Output is correct
58 Correct 245 ms 23980 KB Output is correct
59 Correct 87 ms 7404 KB Output is correct
60 Correct 229 ms 23264 KB Output is correct
61 Correct 241 ms 22832 KB Output is correct
62 Correct 245 ms 24108 KB Output is correct
63 Correct 356 ms 25588 KB Output is correct
64 Correct 1 ms 620 KB Output is correct
65 Correct 1 ms 748 KB Output is correct
66 Correct 1 ms 748 KB Output is correct
67 Correct 2 ms 748 KB Output is correct
68 Correct 1 ms 748 KB Output is correct
69 Correct 2 ms 876 KB Output is correct
70 Correct 2 ms 876 KB Output is correct
71 Correct 2 ms 876 KB Output is correct
72 Correct 1 ms 748 KB Output is correct
73 Correct 2 ms 876 KB Output is correct
74 Runtime error 106 ms 17756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
75 Halted 0 ms 0 KB -