답안 #731816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731816 2023-04-28T03:32:50 Z stevancv 자매 도시 (APIO20_swap) C++14
100 / 100
355 ms 61752 KB
#include <bits/stdc++.h>
#include "swap.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 2e9 + 2;
int link[3 * N], ok[3 * N], mx[3 * N], cnt[N], tsz;
vector<int> g[3 * N];
int Find(int x) {
    if (x == link[x]) return x;
    return link[x] = Find(link[x]);
}
int par[3 * N][19], in[3 * N], out[3 * N], koji[3 * N];
void Dfs(int s, int e, int v) {
    if (ok[s] == 1) v = s;
    koji[s] = v;
    in[s] = ++tsz;
    par[s][0] = e;
    for (int i = 1; i < 19; i++) par[s][i] = par[par[s][i - 1]][i - 1];
    for (int u : g[s]) {
        Dfs(u, s, v);
    }
    out[s] = tsz;
}
bool Ancestor(int u, int v) {
    return in[u] <= in[v] && out[v] <= out[u];
}
int Lca(int u, int v) {
    if (Ancestor(u, v)) return u;
    if (Ancestor(v, u)) return v;
    for (int i = 18; i >= 0; i--) {
        if (par[u][i] && !Ancestor(par[u][i], v)) u = par[u][i];
    }
    return par[u][0];
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w) {
    vector<array<int, 3>> e;
    for (int i = 0; i < m; i++) {
        u[i] += 1; v[i] += 1;
        e.push_back({w[i], u[i], v[i]});
    }
    sort(e.begin(), e.end());
    for (int i = 1; i <= n; i++) link[i] = i;
    tsz = n;
    for (auto u : e) {
        int c = u[0]; int a = u[1]; int b = u[2];
        int aa = a; int bb = b;
        if (Find(a) != Find(b)) {
            cnt[a] += 1; cnt[b] += 1; tsz += 1;
            a = Find(a); b = Find(b);
            g[tsz].push_back(a);
            g[tsz].push_back(b);
            link[a] = link[b] = link[tsz] = tsz;
            if (ok[a] || ok[b] || cnt[aa] >= 3 || cnt[bb] >= 3) ok[tsz] = 1;
            mx[tsz] = c;
            continue;
        }
        cnt[a] += 1; cnt[b] += 1; tsz += 1;
        a = Find(a);
        g[tsz].push_back(a);
        link[a] = link[tsz] = tsz;
        ok[tsz] = 1;
        mx[tsz] = c;
    }
    tsz = 0;
    Dfs(n + m, 0, 0);
}
int getMinimumFuelCapacity(int x, int y) {
    x += 1; y += 1;
    int o = koji[Lca(x, y)];
  	if (mx[o] == 0) return -1;
    return mx[o];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7344 KB Output is correct
4 Correct 5 ms 7508 KB Output is correct
5 Correct 7 ms 7636 KB Output is correct
6 Correct 7 ms 7636 KB Output is correct
7 Correct 7 ms 7632 KB Output is correct
8 Correct 5 ms 7632 KB Output is correct
9 Correct 97 ms 28988 KB Output is correct
10 Correct 117 ms 33804 KB Output is correct
11 Correct 148 ms 33404 KB Output is correct
12 Correct 141 ms 34868 KB Output is correct
13 Correct 104 ms 37192 KB Output is correct
14 Correct 106 ms 29244 KB Output is correct
15 Correct 201 ms 37776 KB Output is correct
16 Correct 189 ms 37168 KB Output is correct
17 Correct 226 ms 38720 KB Output is correct
18 Correct 240 ms 41040 KB Output is correct
19 Correct 77 ms 16608 KB Output is correct
20 Correct 227 ms 38056 KB Output is correct
21 Correct 181 ms 37468 KB Output is correct
22 Correct 202 ms 39176 KB Output is correct
23 Correct 265 ms 41608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 241 ms 41904 KB Output is correct
4 Correct 274 ms 43324 KB Output is correct
5 Correct 242 ms 42696 KB Output is correct
6 Correct 268 ms 43168 KB Output is correct
7 Correct 253 ms 43156 KB Output is correct
8 Correct 294 ms 41900 KB Output is correct
9 Correct 237 ms 42688 KB Output is correct
10 Correct 271 ms 41556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7344 KB Output is correct
4 Correct 5 ms 7508 KB Output is correct
5 Correct 7 ms 7636 KB Output is correct
6 Correct 7 ms 7636 KB Output is correct
7 Correct 7 ms 7632 KB Output is correct
8 Correct 5 ms 7632 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 7636 KB Output is correct
11 Correct 5 ms 7636 KB Output is correct
12 Correct 5 ms 7636 KB Output is correct
13 Correct 5 ms 7508 KB Output is correct
14 Correct 5 ms 7624 KB Output is correct
15 Correct 5 ms 7636 KB Output is correct
16 Correct 5 ms 7636 KB Output is correct
17 Correct 6 ms 7636 KB Output is correct
18 Correct 5 ms 7636 KB Output is correct
19 Correct 5 ms 7636 KB Output is correct
20 Correct 4 ms 7636 KB Output is correct
21 Correct 5 ms 7628 KB Output is correct
22 Correct 5 ms 7764 KB Output is correct
23 Correct 4 ms 7500 KB Output is correct
24 Correct 5 ms 7796 KB Output is correct
25 Correct 5 ms 7764 KB Output is correct
26 Correct 5 ms 7764 KB Output is correct
27 Correct 6 ms 7628 KB Output is correct
28 Correct 6 ms 7892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7344 KB Output is correct
5 Correct 5 ms 7508 KB Output is correct
6 Correct 7 ms 7636 KB Output is correct
7 Correct 7 ms 7636 KB Output is correct
8 Correct 7 ms 7632 KB Output is correct
9 Correct 5 ms 7632 KB Output is correct
10 Correct 97 ms 28988 KB Output is correct
11 Correct 117 ms 33804 KB Output is correct
12 Correct 148 ms 33404 KB Output is correct
13 Correct 141 ms 34868 KB Output is correct
14 Correct 104 ms 37192 KB Output is correct
15 Correct 5 ms 7636 KB Output is correct
16 Correct 5 ms 7636 KB Output is correct
17 Correct 5 ms 7636 KB Output is correct
18 Correct 5 ms 7508 KB Output is correct
19 Correct 5 ms 7624 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 5 ms 7636 KB Output is correct
22 Correct 6 ms 7636 KB Output is correct
23 Correct 5 ms 7636 KB Output is correct
24 Correct 5 ms 7636 KB Output is correct
25 Correct 4 ms 7636 KB Output is correct
26 Correct 5 ms 7628 KB Output is correct
27 Correct 5 ms 7764 KB Output is correct
28 Correct 4 ms 7500 KB Output is correct
29 Correct 5 ms 7796 KB Output is correct
30 Correct 5 ms 7764 KB Output is correct
31 Correct 5 ms 7764 KB Output is correct
32 Correct 6 ms 7628 KB Output is correct
33 Correct 6 ms 7892 KB Output is correct
34 Correct 15 ms 11116 KB Output is correct
35 Correct 117 ms 34656 KB Output is correct
36 Correct 140 ms 34752 KB Output is correct
37 Correct 122 ms 34836 KB Output is correct
38 Correct 132 ms 34484 KB Output is correct
39 Correct 118 ms 34368 KB Output is correct
40 Correct 122 ms 32220 KB Output is correct
41 Correct 123 ms 34876 KB Output is correct
42 Correct 130 ms 34620 KB Output is correct
43 Correct 104 ms 38112 KB Output is correct
44 Correct 134 ms 35392 KB Output is correct
45 Correct 145 ms 46268 KB Output is correct
46 Correct 126 ms 34732 KB Output is correct
47 Correct 145 ms 35148 KB Output is correct
48 Correct 170 ms 38708 KB Output is correct
49 Correct 106 ms 43448 KB Output is correct
50 Correct 94 ms 35608 KB Output is correct
51 Correct 133 ms 41096 KB Output is correct
52 Correct 178 ms 49168 KB Output is correct
53 Correct 196 ms 52536 KB Output is correct
54 Correct 230 ms 57824 KB Output is correct
55 Correct 122 ms 37820 KB Output is correct
56 Correct 193 ms 53364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7344 KB Output is correct
4 Correct 5 ms 7508 KB Output is correct
5 Correct 7 ms 7636 KB Output is correct
6 Correct 7 ms 7636 KB Output is correct
7 Correct 7 ms 7632 KB Output is correct
8 Correct 5 ms 7632 KB Output is correct
9 Correct 97 ms 28988 KB Output is correct
10 Correct 117 ms 33804 KB Output is correct
11 Correct 148 ms 33404 KB Output is correct
12 Correct 141 ms 34868 KB Output is correct
13 Correct 104 ms 37192 KB Output is correct
14 Correct 106 ms 29244 KB Output is correct
15 Correct 201 ms 37776 KB Output is correct
16 Correct 189 ms 37168 KB Output is correct
17 Correct 226 ms 38720 KB Output is correct
18 Correct 240 ms 41040 KB Output is correct
19 Correct 241 ms 41904 KB Output is correct
20 Correct 274 ms 43324 KB Output is correct
21 Correct 242 ms 42696 KB Output is correct
22 Correct 268 ms 43168 KB Output is correct
23 Correct 253 ms 43156 KB Output is correct
24 Correct 294 ms 41900 KB Output is correct
25 Correct 237 ms 42688 KB Output is correct
26 Correct 271 ms 41556 KB Output is correct
27 Correct 5 ms 7636 KB Output is correct
28 Correct 5 ms 7636 KB Output is correct
29 Correct 5 ms 7636 KB Output is correct
30 Correct 5 ms 7508 KB Output is correct
31 Correct 5 ms 7624 KB Output is correct
32 Correct 5 ms 7636 KB Output is correct
33 Correct 5 ms 7636 KB Output is correct
34 Correct 6 ms 7636 KB Output is correct
35 Correct 5 ms 7636 KB Output is correct
36 Correct 15 ms 11116 KB Output is correct
37 Correct 117 ms 34656 KB Output is correct
38 Correct 140 ms 34752 KB Output is correct
39 Correct 122 ms 34836 KB Output is correct
40 Correct 132 ms 34484 KB Output is correct
41 Correct 118 ms 34368 KB Output is correct
42 Correct 122 ms 32220 KB Output is correct
43 Correct 123 ms 34876 KB Output is correct
44 Correct 130 ms 34620 KB Output is correct
45 Correct 104 ms 38112 KB Output is correct
46 Correct 134 ms 35392 KB Output is correct
47 Correct 28 ms 11232 KB Output is correct
48 Correct 205 ms 38548 KB Output is correct
49 Correct 189 ms 38632 KB Output is correct
50 Correct 201 ms 38720 KB Output is correct
51 Correct 195 ms 38652 KB Output is correct
52 Correct 180 ms 36932 KB Output is correct
53 Correct 163 ms 30972 KB Output is correct
54 Correct 202 ms 39228 KB Output is correct
55 Correct 214 ms 38488 KB Output is correct
56 Correct 253 ms 41268 KB Output is correct
57 Correct 211 ms 39696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7344 KB Output is correct
5 Correct 5 ms 7508 KB Output is correct
6 Correct 7 ms 7636 KB Output is correct
7 Correct 7 ms 7636 KB Output is correct
8 Correct 7 ms 7632 KB Output is correct
9 Correct 5 ms 7632 KB Output is correct
10 Correct 97 ms 28988 KB Output is correct
11 Correct 117 ms 33804 KB Output is correct
12 Correct 148 ms 33404 KB Output is correct
13 Correct 141 ms 34868 KB Output is correct
14 Correct 104 ms 37192 KB Output is correct
15 Correct 106 ms 29244 KB Output is correct
16 Correct 201 ms 37776 KB Output is correct
17 Correct 189 ms 37168 KB Output is correct
18 Correct 226 ms 38720 KB Output is correct
19 Correct 240 ms 41040 KB Output is correct
20 Correct 241 ms 41904 KB Output is correct
21 Correct 274 ms 43324 KB Output is correct
22 Correct 242 ms 42696 KB Output is correct
23 Correct 268 ms 43168 KB Output is correct
24 Correct 253 ms 43156 KB Output is correct
25 Correct 294 ms 41900 KB Output is correct
26 Correct 237 ms 42688 KB Output is correct
27 Correct 271 ms 41556 KB Output is correct
28 Correct 5 ms 7636 KB Output is correct
29 Correct 5 ms 7636 KB Output is correct
30 Correct 5 ms 7636 KB Output is correct
31 Correct 5 ms 7508 KB Output is correct
32 Correct 5 ms 7624 KB Output is correct
33 Correct 5 ms 7636 KB Output is correct
34 Correct 5 ms 7636 KB Output is correct
35 Correct 6 ms 7636 KB Output is correct
36 Correct 5 ms 7636 KB Output is correct
37 Correct 15 ms 11116 KB Output is correct
38 Correct 117 ms 34656 KB Output is correct
39 Correct 140 ms 34752 KB Output is correct
40 Correct 122 ms 34836 KB Output is correct
41 Correct 132 ms 34484 KB Output is correct
42 Correct 118 ms 34368 KB Output is correct
43 Correct 122 ms 32220 KB Output is correct
44 Correct 123 ms 34876 KB Output is correct
45 Correct 130 ms 34620 KB Output is correct
46 Correct 104 ms 38112 KB Output is correct
47 Correct 134 ms 35392 KB Output is correct
48 Correct 28 ms 11232 KB Output is correct
49 Correct 205 ms 38548 KB Output is correct
50 Correct 189 ms 38632 KB Output is correct
51 Correct 201 ms 38720 KB Output is correct
52 Correct 195 ms 38652 KB Output is correct
53 Correct 180 ms 36932 KB Output is correct
54 Correct 163 ms 30972 KB Output is correct
55 Correct 202 ms 39228 KB Output is correct
56 Correct 214 ms 38488 KB Output is correct
57 Correct 253 ms 41268 KB Output is correct
58 Correct 211 ms 39696 KB Output is correct
59 Correct 77 ms 16608 KB Output is correct
60 Correct 227 ms 38056 KB Output is correct
61 Correct 181 ms 37468 KB Output is correct
62 Correct 202 ms 39176 KB Output is correct
63 Correct 265 ms 41608 KB Output is correct
64 Correct 5 ms 7636 KB Output is correct
65 Correct 4 ms 7636 KB Output is correct
66 Correct 5 ms 7628 KB Output is correct
67 Correct 5 ms 7764 KB Output is correct
68 Correct 4 ms 7500 KB Output is correct
69 Correct 5 ms 7796 KB Output is correct
70 Correct 5 ms 7764 KB Output is correct
71 Correct 5 ms 7764 KB Output is correct
72 Correct 6 ms 7628 KB Output is correct
73 Correct 6 ms 7892 KB Output is correct
74 Correct 145 ms 46268 KB Output is correct
75 Correct 126 ms 34732 KB Output is correct
76 Correct 145 ms 35148 KB Output is correct
77 Correct 170 ms 38708 KB Output is correct
78 Correct 106 ms 43448 KB Output is correct
79 Correct 94 ms 35608 KB Output is correct
80 Correct 133 ms 41096 KB Output is correct
81 Correct 178 ms 49168 KB Output is correct
82 Correct 196 ms 52536 KB Output is correct
83 Correct 230 ms 57824 KB Output is correct
84 Correct 122 ms 37820 KB Output is correct
85 Correct 193 ms 53364 KB Output is correct
86 Correct 83 ms 21760 KB Output is correct
87 Correct 212 ms 38708 KB Output is correct
88 Correct 208 ms 38744 KB Output is correct
89 Correct 264 ms 40988 KB Output is correct
90 Correct 200 ms 48948 KB Output is correct
91 Correct 217 ms 45928 KB Output is correct
92 Correct 279 ms 43472 KB Output is correct
93 Correct 274 ms 52420 KB Output is correct
94 Correct 355 ms 56252 KB Output is correct
95 Correct 301 ms 61752 KB Output is correct
96 Correct 249 ms 41400 KB Output is correct
97 Correct 326 ms 48588 KB Output is correct