# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398139 | 2021-05-03T19:14:23 Z | ZikXewen | Swapping Cities (APIO20_swap) | C++17 | 681 ms | 57372 KB |
#include "swap.h" #include <bits/stdc++.h> using namespace std; typedef tuple<int, int, int> ii; const int X = 1e5 + 5, R = 1e9 + 5, L = 20; int N, M, CT; vector<ii> ed; struct node{ int nl, e1, e2, id, dp; node *pa[L], *ppa; node* fd(){return ppa? ppa = ppa -> fd() : this;} void ste(int u, int v){e1 = u, e2 = v;} void stp(node *u){pa[0] = ppa = u;} node(int u) : id(u), nl(), e1(u), e2(u), pa(), ppa(), dp() {} } *tr[X << 1]; void un(int u, int v, int po){ node *pu = tr[u] -> fd(), *pv = tr[v] -> fd(); if(pu == pv){ if(!pu -> nl) pu -> nl = po; return; } node *nw = tr[CT++] = new node(CT); pu -> stp(nw), pv -> stp(nw); if(pv -> nl or pu -> nl) return nw -> nl = po, void(); if(u == pu -> e1 and v == pv -> e1) return nw -> ste(pu -> e2, pv -> e2), void(); if(u == pu -> e1 and v == pv -> e2) return nw -> ste(pu -> e2, pv -> e1), void(); if(u == pu -> e2 and v == pv -> e1) return nw -> ste(pu -> e1, pv -> e2), void(); if(u == pu -> e2 and v == pv -> e2) return nw -> ste(pu -> e1, pv -> e1), void(); nw -> nl = po; } void init(int _N, int _M, vector<int> U, vector<int> V, vector<int> W) { N = _N; M = _M; for(int i = 0; i < N; ++i) tr[CT++] = new node(i); for(int i = 0; i < M; ++i) ed.emplace_back(U[i], V[i], W[i]); sort(ed.begin(), ed.end(), [=](ii u, ii v){return get<2>(u) < get<2>(v);}); for(auto [u, v, w]: ed) un(u, v, w); tr[CT - 1] -> dp = 1; for(int i = 1; i < L; ++i) for(int j = 0; j < CT; ++j) if(tr[j] -> pa[i - 1]) { tr[j] -> pa[i] = tr[j] -> pa[i - 1] -> pa[i - 1]; if(tr[j] -> pa[i - 1] -> dp) tr[j] -> dp = tr[j] -> pa[i - 1] -> dp + (1 << (i - 1)); } } int getMinimumFuelCapacity(int u, int v) { node *pu = tr[u], *pv = tr[v]; if(pu -> dp < pv -> dp) swap(pu, pv); for(int i = L - 1; i >= 0; --i) if(pu -> pa[i] and pu -> pa[i] -> dp >= pv -> dp) pu = pu -> pa[i]; if(pu != pv){ for(int i = L - 1; i >= 0; --i) if(pu -> pa[i] != pv -> pa[i]) pu = pu -> pa[i], pv = pv -> pa[i]; pu = pu -> pa[0]; } if(pu -> nl) return pu -> nl; for(int i = L - 1; i >= 0; --i) if(pu -> pa[i] and !pu -> pa[i] -> nl) pu = pu -> pa[i]; return pu -> pa[0]? pu -> pa[0] -> nl : -1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 460 KB | Output is correct |
5 | Correct | 1 ms | 716 KB | Output is correct |
6 | Correct | 1 ms | 704 KB | Output is correct |
7 | Correct | 2 ms | 716 KB | Output is correct |
8 | Correct | 2 ms | 716 KB | Output is correct |
9 | Correct | 124 ms | 37808 KB | Output is correct |
10 | Correct | 152 ms | 46384 KB | Output is correct |
11 | Correct | 146 ms | 45536 KB | Output is correct |
12 | Correct | 156 ms | 48188 KB | Output is correct |
13 | Correct | 178 ms | 48944 KB | Output is correct |
14 | Correct | 144 ms | 38076 KB | Output is correct |
15 | Correct | 367 ms | 50676 KB | Output is correct |
16 | Correct | 363 ms | 49396 KB | Output is correct |
17 | Correct | 389 ms | 52256 KB | Output is correct |
18 | Correct | 663 ms | 52976 KB | Output is correct |
19 | Correct | 124 ms | 12916 KB | Output is correct |
20 | Correct | 354 ms | 51904 KB | Output is correct |
21 | Correct | 354 ms | 50420 KB | Output is correct |
22 | Correct | 369 ms | 53608 KB | Output is correct |
23 | Correct | 681 ms | 54412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 571 ms | 50372 KB | Output is correct |
4 | Correct | 571 ms | 52624 KB | Output is correct |
5 | Correct | 592 ms | 51484 KB | Output is correct |
6 | Correct | 563 ms | 52452 KB | Output is correct |
7 | Correct | 588 ms | 52152 KB | Output is correct |
8 | Correct | 564 ms | 50064 KB | Output is correct |
9 | Correct | 591 ms | 51696 KB | Output is correct |
10 | Correct | 579 ms | 49816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 460 KB | Output is correct |
5 | Correct | 1 ms | 716 KB | Output is correct |
6 | Correct | 1 ms | 704 KB | Output is correct |
7 | Correct | 2 ms | 716 KB | Output is correct |
8 | Correct | 2 ms | 716 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 2 ms | 700 KB | Output is correct |
11 | Correct | 1 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 716 KB | Output is correct |
13 | Correct | 1 ms | 588 KB | Output is correct |
14 | Correct | 2 ms | 588 KB | Output is correct |
15 | Correct | 2 ms | 716 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
17 | Correct | 1 ms | 716 KB | Output is correct |
18 | Correct | 2 ms | 716 KB | Output is correct |
19 | Correct | 2 ms | 592 KB | Output is correct |
20 | Correct | 1 ms | 716 KB | Output is correct |
21 | Correct | 2 ms | 720 KB | Output is correct |
22 | Correct | 1 ms | 460 KB | Output is correct |
23 | Correct | 1 ms | 572 KB | Output is correct |
24 | Correct | 2 ms | 716 KB | Output is correct |
25 | Correct | 2 ms | 716 KB | Output is correct |
26 | Correct | 2 ms | 716 KB | Output is correct |
27 | Correct | 1 ms | 716 KB | Output is correct |
28 | Correct | 2 ms | 716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 460 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 704 KB | Output is correct |
8 | Correct | 2 ms | 716 KB | Output is correct |
9 | Correct | 2 ms | 716 KB | Output is correct |
10 | Correct | 124 ms | 37808 KB | Output is correct |
11 | Correct | 152 ms | 46384 KB | Output is correct |
12 | Correct | 146 ms | 45536 KB | Output is correct |
13 | Correct | 156 ms | 48188 KB | Output is correct |
14 | Correct | 178 ms | 48944 KB | Output is correct |
15 | Correct | 2 ms | 700 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
17 | Correct | 1 ms | 716 KB | Output is correct |
18 | Correct | 1 ms | 588 KB | Output is correct |
19 | Correct | 2 ms | 588 KB | Output is correct |
20 | Correct | 2 ms | 716 KB | Output is correct |
21 | Correct | 1 ms | 716 KB | Output is correct |
22 | Correct | 1 ms | 716 KB | Output is correct |
23 | Correct | 2 ms | 716 KB | Output is correct |
24 | Correct | 2 ms | 592 KB | Output is correct |
25 | Correct | 1 ms | 716 KB | Output is correct |
26 | Correct | 2 ms | 720 KB | Output is correct |
27 | Correct | 1 ms | 460 KB | Output is correct |
28 | Correct | 1 ms | 572 KB | Output is correct |
29 | Correct | 2 ms | 716 KB | Output is correct |
30 | Correct | 2 ms | 716 KB | Output is correct |
31 | Correct | 2 ms | 716 KB | Output is correct |
32 | Correct | 1 ms | 716 KB | Output is correct |
33 | Correct | 2 ms | 716 KB | Output is correct |
34 | Correct | 16 ms | 6800 KB | Output is correct |
35 | Correct | 155 ms | 47912 KB | Output is correct |
36 | Correct | 157 ms | 47796 KB | Output is correct |
37 | Correct | 154 ms | 47748 KB | Output is correct |
38 | Correct | 164 ms | 47288 KB | Output is correct |
39 | Correct | 156 ms | 46868 KB | Output is correct |
40 | Correct | 145 ms | 43044 KB | Output is correct |
41 | Correct | 154 ms | 48164 KB | Output is correct |
42 | Correct | 152 ms | 47804 KB | Output is correct |
43 | Correct | 169 ms | 47796 KB | Output is correct |
44 | Correct | 170 ms | 48188 KB | Output is correct |
45 | Correct | 208 ms | 41812 KB | Output is correct |
46 | Correct | 153 ms | 47800 KB | Output is correct |
47 | Correct | 161 ms | 47676 KB | Output is correct |
48 | Correct | 194 ms | 47288 KB | Output is correct |
49 | Correct | 70 ms | 10160 KB | Output is correct |
50 | Correct | 60 ms | 9888 KB | Output is correct |
51 | Correct | 162 ms | 34428 KB | Output is correct |
52 | Correct | 211 ms | 51596 KB | Output is correct |
53 | Correct | 240 ms | 52664 KB | Output is correct |
54 | Correct | 231 ms | 53560 KB | Output is correct |
55 | Correct | 169 ms | 47924 KB | Output is correct |
56 | Correct | 258 ms | 52212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 460 KB | Output is correct |
5 | Correct | 1 ms | 716 KB | Output is correct |
6 | Correct | 1 ms | 704 KB | Output is correct |
7 | Correct | 2 ms | 716 KB | Output is correct |
8 | Correct | 2 ms | 716 KB | Output is correct |
9 | Correct | 124 ms | 37808 KB | Output is correct |
10 | Correct | 152 ms | 46384 KB | Output is correct |
11 | Correct | 146 ms | 45536 KB | Output is correct |
12 | Correct | 156 ms | 48188 KB | Output is correct |
13 | Correct | 178 ms | 48944 KB | Output is correct |
14 | Correct | 144 ms | 38076 KB | Output is correct |
15 | Correct | 367 ms | 50676 KB | Output is correct |
16 | Correct | 363 ms | 49396 KB | Output is correct |
17 | Correct | 389 ms | 52256 KB | Output is correct |
18 | Correct | 663 ms | 52976 KB | Output is correct |
19 | Correct | 571 ms | 50372 KB | Output is correct |
20 | Correct | 571 ms | 52624 KB | Output is correct |
21 | Correct | 592 ms | 51484 KB | Output is correct |
22 | Correct | 563 ms | 52452 KB | Output is correct |
23 | Correct | 588 ms | 52152 KB | Output is correct |
24 | Correct | 564 ms | 50064 KB | Output is correct |
25 | Correct | 591 ms | 51696 KB | Output is correct |
26 | Correct | 579 ms | 49816 KB | Output is correct |
27 | Correct | 2 ms | 700 KB | Output is correct |
28 | Correct | 1 ms | 716 KB | Output is correct |
29 | Correct | 1 ms | 716 KB | Output is correct |
30 | Correct | 1 ms | 588 KB | Output is correct |
31 | Correct | 2 ms | 588 KB | Output is correct |
32 | Correct | 2 ms | 716 KB | Output is correct |
33 | Correct | 1 ms | 716 KB | Output is correct |
34 | Correct | 1 ms | 716 KB | Output is correct |
35 | Correct | 2 ms | 716 KB | Output is correct |
36 | Correct | 16 ms | 6800 KB | Output is correct |
37 | Correct | 155 ms | 47912 KB | Output is correct |
38 | Correct | 157 ms | 47796 KB | Output is correct |
39 | Correct | 154 ms | 47748 KB | Output is correct |
40 | Correct | 164 ms | 47288 KB | Output is correct |
41 | Correct | 156 ms | 46868 KB | Output is correct |
42 | Correct | 145 ms | 43044 KB | Output is correct |
43 | Correct | 154 ms | 48164 KB | Output is correct |
44 | Correct | 152 ms | 47804 KB | Output is correct |
45 | Correct | 169 ms | 47796 KB | Output is correct |
46 | Correct | 170 ms | 48188 KB | Output is correct |
47 | Correct | 26 ms | 6676 KB | Output is correct |
48 | Correct | 356 ms | 52668 KB | Output is correct |
49 | Correct | 332 ms | 52780 KB | Output is correct |
50 | Correct | 319 ms | 52640 KB | Output is correct |
51 | Correct | 312 ms | 52620 KB | Output is correct |
52 | Correct | 290 ms | 49640 KB | Output is correct |
53 | Correct | 250 ms | 37800 KB | Output is correct |
54 | Correct | 353 ms | 53664 KB | Output is correct |
55 | Correct | 372 ms | 52768 KB | Output is correct |
56 | Correct | 611 ms | 52768 KB | Output is correct |
57 | Correct | 347 ms | 53664 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 460 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 704 KB | Output is correct |
8 | Correct | 2 ms | 716 KB | Output is correct |
9 | Correct | 2 ms | 716 KB | Output is correct |
10 | Correct | 124 ms | 37808 KB | Output is correct |
11 | Correct | 152 ms | 46384 KB | Output is correct |
12 | Correct | 146 ms | 45536 KB | Output is correct |
13 | Correct | 156 ms | 48188 KB | Output is correct |
14 | Correct | 178 ms | 48944 KB | Output is correct |
15 | Correct | 144 ms | 38076 KB | Output is correct |
16 | Correct | 367 ms | 50676 KB | Output is correct |
17 | Correct | 363 ms | 49396 KB | Output is correct |
18 | Correct | 389 ms | 52256 KB | Output is correct |
19 | Correct | 663 ms | 52976 KB | Output is correct |
20 | Correct | 571 ms | 50372 KB | Output is correct |
21 | Correct | 571 ms | 52624 KB | Output is correct |
22 | Correct | 592 ms | 51484 KB | Output is correct |
23 | Correct | 563 ms | 52452 KB | Output is correct |
24 | Correct | 588 ms | 52152 KB | Output is correct |
25 | Correct | 564 ms | 50064 KB | Output is correct |
26 | Correct | 591 ms | 51696 KB | Output is correct |
27 | Correct | 579 ms | 49816 KB | Output is correct |
28 | Correct | 2 ms | 700 KB | Output is correct |
29 | Correct | 1 ms | 716 KB | Output is correct |
30 | Correct | 1 ms | 716 KB | Output is correct |
31 | Correct | 1 ms | 588 KB | Output is correct |
32 | Correct | 2 ms | 588 KB | Output is correct |
33 | Correct | 2 ms | 716 KB | Output is correct |
34 | Correct | 1 ms | 716 KB | Output is correct |
35 | Correct | 1 ms | 716 KB | Output is correct |
36 | Correct | 2 ms | 716 KB | Output is correct |
37 | Correct | 16 ms | 6800 KB | Output is correct |
38 | Correct | 155 ms | 47912 KB | Output is correct |
39 | Correct | 157 ms | 47796 KB | Output is correct |
40 | Correct | 154 ms | 47748 KB | Output is correct |
41 | Correct | 164 ms | 47288 KB | Output is correct |
42 | Correct | 156 ms | 46868 KB | Output is correct |
43 | Correct | 145 ms | 43044 KB | Output is correct |
44 | Correct | 154 ms | 48164 KB | Output is correct |
45 | Correct | 152 ms | 47804 KB | Output is correct |
46 | Correct | 169 ms | 47796 KB | Output is correct |
47 | Correct | 170 ms | 48188 KB | Output is correct |
48 | Correct | 26 ms | 6676 KB | Output is correct |
49 | Correct | 356 ms | 52668 KB | Output is correct |
50 | Correct | 332 ms | 52780 KB | Output is correct |
51 | Correct | 319 ms | 52640 KB | Output is correct |
52 | Correct | 312 ms | 52620 KB | Output is correct |
53 | Correct | 290 ms | 49640 KB | Output is correct |
54 | Correct | 250 ms | 37800 KB | Output is correct |
55 | Correct | 353 ms | 53664 KB | Output is correct |
56 | Correct | 372 ms | 52768 KB | Output is correct |
57 | Correct | 611 ms | 52768 KB | Output is correct |
58 | Correct | 347 ms | 53664 KB | Output is correct |
59 | Correct | 124 ms | 12916 KB | Output is correct |
60 | Correct | 354 ms | 51904 KB | Output is correct |
61 | Correct | 354 ms | 50420 KB | Output is correct |
62 | Correct | 369 ms | 53608 KB | Output is correct |
63 | Correct | 681 ms | 54412 KB | Output is correct |
64 | Correct | 2 ms | 592 KB | Output is correct |
65 | Correct | 1 ms | 716 KB | Output is correct |
66 | Correct | 2 ms | 720 KB | Output is correct |
67 | Correct | 1 ms | 460 KB | Output is correct |
68 | Correct | 1 ms | 572 KB | Output is correct |
69 | Correct | 2 ms | 716 KB | Output is correct |
70 | Correct | 2 ms | 716 KB | Output is correct |
71 | Correct | 2 ms | 716 KB | Output is correct |
72 | Correct | 1 ms | 716 KB | Output is correct |
73 | Correct | 2 ms | 716 KB | Output is correct |
74 | Correct | 208 ms | 41812 KB | Output is correct |
75 | Correct | 153 ms | 47800 KB | Output is correct |
76 | Correct | 161 ms | 47676 KB | Output is correct |
77 | Correct | 194 ms | 47288 KB | Output is correct |
78 | Correct | 70 ms | 10160 KB | Output is correct |
79 | Correct | 60 ms | 9888 KB | Output is correct |
80 | Correct | 162 ms | 34428 KB | Output is correct |
81 | Correct | 211 ms | 51596 KB | Output is correct |
82 | Correct | 240 ms | 52664 KB | Output is correct |
83 | Correct | 231 ms | 53560 KB | Output is correct |
84 | Correct | 169 ms | 47924 KB | Output is correct |
85 | Correct | 258 ms | 52212 KB | Output is correct |
86 | Correct | 109 ms | 17260 KB | Output is correct |
87 | Correct | 312 ms | 52744 KB | Output is correct |
88 | Correct | 314 ms | 52772 KB | Output is correct |
89 | Correct | 456 ms | 49196 KB | Output is correct |
90 | Correct | 176 ms | 14128 KB | Output is correct |
91 | Correct | 207 ms | 17516 KB | Output is correct |
92 | Correct | 404 ms | 39396 KB | Output is correct |
93 | Correct | 364 ms | 56200 KB | Output is correct |
94 | Correct | 447 ms | 57364 KB | Output is correct |
95 | Correct | 436 ms | 57372 KB | Output is correct |
96 | Correct | 617 ms | 52892 KB | Output is correct |
97 | Correct | 499 ms | 55284 KB | Output is correct |