Submission #824032

# Submission time Handle Problem Language Result Execution time Memory
824032 2023-08-13T11:44:52 Z abczz Swapping Cities (APIO20_swap) C++14
100 / 100
689 ms 56112 KB
#include "swap.h"
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#define ll long long
 
using namespace std;
 
ll cnt, P[200000];
ll X[200000], D[200000], bl[19][200000], in[200000];
array<ll, 2> chd[200000];
bool B[200000];
vector <array<ll, 3>> E;
ll dsu(ll u) {
  if (P[u] == u) return u;
  else return P[u] = dsu(P[u]);
}
 
void dfs(ll u, ll w) {
  if (u == -1) return;
  D[u] = w;
  dfs(chd[u][0], w+1);
  dfs(chd[u][1], w+1);
}
 
ll lca(ll a, ll b) {
  if (D[a] < D[b]) swap(a, b);
  ll da = D[a];
  for (int i=18; i>=0; --i) {
    if (da-D[b] >= (1LL<<i)) {
      da -= (1LL<<i);
      a = bl[i][a];
    }
  }
  for (int i=18; i>=0; --i) {
    if (bl[i][a] != bl[i][b]) {
      a = bl[i][a], b = bl[i][b];
    }
  }
  if (a != b) {
    a = bl[0][a], b = bl[0][b];
  }
  for (int i=18; i>=0; --i) {
    if (!B[bl[i][a]]) {
      a = bl[i][a];
    }
  }
  if (!B[a]) a = bl[0][a];
  return B[a] == 1 ? X[a] : -1;
}
 
void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
  ll a, b;
  for (int i=0; i<N; ++i) {
    chd[i] = {-1, -1};
  }
  for (int i=0; i<2*N; ++i) {
    P[i] = i;
    X[i] = 1e18;
  }
  for (int i=0; i<M; ++i) {
    E.push_back({W[i], U[i], V[i]});
  }
  cnt = N;
  sort(E.begin(), E.end());
  for (auto [w, u, v] : E) {
    ++in[u], ++in[v];
    a = dsu(u), b = dsu(v);
    if (a != b) {
      bl[0][a] = bl[0][b] = cnt;
      chd[cnt] = {a, b};
      P[a] = P[b] = cnt;
      B[cnt] = B[a] | B[b];
      X[cnt] = w;
      if (in[u] >= 3 || in[v] >= 3) {
        B[cnt] = 1;
        X[cnt] = w;
      }
      ++cnt;
    }
    else if (!B[a]) {
      B[a] = 1;
      X[a] = w;
    }
  }
  --cnt;
  dfs(cnt, 0);
  bl[0][cnt] = cnt;
  for (int i=1; i<19; ++i) {
    for (int j=0; j<=cnt; ++j) {
      bl[i][j] = bl[i-1][bl[i-1][j]];
    }
  }
}
 
int getMinimumFuelCapacity(int X, int Y) {
  return lca(X, Y);
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:68:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |   for (auto [w, u, v] : E) {
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 568 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 43 ms 36032 KB Output is correct
10 Correct 63 ms 43888 KB Output is correct
11 Correct 58 ms 43360 KB Output is correct
12 Correct 56 ms 45612 KB Output is correct
13 Correct 53 ms 46264 KB Output is correct
14 Correct 74 ms 36284 KB Output is correct
15 Correct 453 ms 48216 KB Output is correct
16 Correct 423 ms 47016 KB Output is correct
17 Correct 442 ms 49568 KB Output is correct
18 Correct 509 ms 50220 KB Output is correct
19 Correct 112 ms 12768 KB Output is correct
20 Correct 397 ms 49440 KB Output is correct
21 Correct 434 ms 48096 KB Output is correct
22 Correct 409 ms 50980 KB Output is correct
23 Correct 490 ms 51616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 629 ms 49796 KB Output is correct
4 Correct 584 ms 52008 KB Output is correct
5 Correct 663 ms 50820 KB Output is correct
6 Correct 620 ms 51824 KB Output is correct
7 Correct 689 ms 51492 KB Output is correct
8 Correct 607 ms 49552 KB Output is correct
9 Correct 612 ms 51088 KB Output is correct
10 Correct 653 ms 49144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 568 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 832 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 708 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 832 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 568 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 43 ms 36032 KB Output is correct
11 Correct 63 ms 43888 KB Output is correct
12 Correct 58 ms 43360 KB Output is correct
13 Correct 56 ms 45612 KB Output is correct
14 Correct 53 ms 46264 KB Output is correct
15 Correct 1 ms 832 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 852 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 852 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 1 ms 708 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 2 ms 980 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 832 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 8 ms 6736 KB Output is correct
35 Correct 52 ms 45352 KB Output is correct
36 Correct 53 ms 45372 KB Output is correct
37 Correct 52 ms 45336 KB Output is correct
38 Correct 54 ms 44856 KB Output is correct
39 Correct 52 ms 44628 KB Output is correct
40 Correct 50 ms 40856 KB Output is correct
41 Correct 56 ms 45640 KB Output is correct
42 Correct 53 ms 45416 KB Output is correct
43 Correct 51 ms 46052 KB Output is correct
44 Correct 55 ms 45628 KB Output is correct
45 Correct 77 ms 41036 KB Output is correct
46 Correct 53 ms 45356 KB Output is correct
47 Correct 54 ms 45244 KB Output is correct
48 Correct 60 ms 45372 KB Output is correct
49 Correct 59 ms 13116 KB Output is correct
50 Correct 43 ms 11452 KB Output is correct
51 Correct 62 ms 33960 KB Output is correct
52 Correct 78 ms 49840 KB Output is correct
53 Correct 85 ms 51120 KB Output is correct
54 Correct 93 ms 52240 KB Output is correct
55 Correct 50 ms 45980 KB Output is correct
56 Correct 88 ms 50800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 568 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 43 ms 36032 KB Output is correct
10 Correct 63 ms 43888 KB Output is correct
11 Correct 58 ms 43360 KB Output is correct
12 Correct 56 ms 45612 KB Output is correct
13 Correct 53 ms 46264 KB Output is correct
14 Correct 74 ms 36284 KB Output is correct
15 Correct 453 ms 48216 KB Output is correct
16 Correct 423 ms 47016 KB Output is correct
17 Correct 442 ms 49568 KB Output is correct
18 Correct 509 ms 50220 KB Output is correct
19 Correct 629 ms 49796 KB Output is correct
20 Correct 584 ms 52008 KB Output is correct
21 Correct 663 ms 50820 KB Output is correct
22 Correct 620 ms 51824 KB Output is correct
23 Correct 689 ms 51492 KB Output is correct
24 Correct 607 ms 49552 KB Output is correct
25 Correct 612 ms 51088 KB Output is correct
26 Correct 653 ms 49144 KB Output is correct
27 Correct 1 ms 832 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 852 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 852 KB Output is correct
34 Correct 1 ms 852 KB Output is correct
35 Correct 1 ms 852 KB Output is correct
36 Correct 8 ms 6736 KB Output is correct
37 Correct 52 ms 45352 KB Output is correct
38 Correct 53 ms 45372 KB Output is correct
39 Correct 52 ms 45336 KB Output is correct
40 Correct 54 ms 44856 KB Output is correct
41 Correct 52 ms 44628 KB Output is correct
42 Correct 50 ms 40856 KB Output is correct
43 Correct 56 ms 45640 KB Output is correct
44 Correct 53 ms 45416 KB Output is correct
45 Correct 51 ms 46052 KB Output is correct
46 Correct 55 ms 45628 KB Output is correct
47 Correct 22 ms 6712 KB Output is correct
48 Correct 427 ms 50056 KB Output is correct
49 Correct 472 ms 50192 KB Output is correct
50 Correct 347 ms 50036 KB Output is correct
51 Correct 340 ms 49824 KB Output is correct
52 Correct 259 ms 47204 KB Output is correct
53 Correct 190 ms 36204 KB Output is correct
54 Correct 442 ms 50984 KB Output is correct
55 Correct 457 ms 50076 KB Output is correct
56 Correct 522 ms 50552 KB Output is correct
57 Correct 273 ms 51004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 568 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 43 ms 36032 KB Output is correct
11 Correct 63 ms 43888 KB Output is correct
12 Correct 58 ms 43360 KB Output is correct
13 Correct 56 ms 45612 KB Output is correct
14 Correct 53 ms 46264 KB Output is correct
15 Correct 74 ms 36284 KB Output is correct
16 Correct 453 ms 48216 KB Output is correct
17 Correct 423 ms 47016 KB Output is correct
18 Correct 442 ms 49568 KB Output is correct
19 Correct 509 ms 50220 KB Output is correct
20 Correct 629 ms 49796 KB Output is correct
21 Correct 584 ms 52008 KB Output is correct
22 Correct 663 ms 50820 KB Output is correct
23 Correct 620 ms 51824 KB Output is correct
24 Correct 689 ms 51492 KB Output is correct
25 Correct 607 ms 49552 KB Output is correct
26 Correct 612 ms 51088 KB Output is correct
27 Correct 653 ms 49144 KB Output is correct
28 Correct 1 ms 832 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 852 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 852 KB Output is correct
34 Correct 1 ms 852 KB Output is correct
35 Correct 1 ms 852 KB Output is correct
36 Correct 1 ms 852 KB Output is correct
37 Correct 8 ms 6736 KB Output is correct
38 Correct 52 ms 45352 KB Output is correct
39 Correct 53 ms 45372 KB Output is correct
40 Correct 52 ms 45336 KB Output is correct
41 Correct 54 ms 44856 KB Output is correct
42 Correct 52 ms 44628 KB Output is correct
43 Correct 50 ms 40856 KB Output is correct
44 Correct 56 ms 45640 KB Output is correct
45 Correct 53 ms 45416 KB Output is correct
46 Correct 51 ms 46052 KB Output is correct
47 Correct 55 ms 45628 KB Output is correct
48 Correct 22 ms 6712 KB Output is correct
49 Correct 427 ms 50056 KB Output is correct
50 Correct 472 ms 50192 KB Output is correct
51 Correct 347 ms 50036 KB Output is correct
52 Correct 340 ms 49824 KB Output is correct
53 Correct 259 ms 47204 KB Output is correct
54 Correct 190 ms 36204 KB Output is correct
55 Correct 442 ms 50984 KB Output is correct
56 Correct 457 ms 50076 KB Output is correct
57 Correct 522 ms 50552 KB Output is correct
58 Correct 273 ms 51004 KB Output is correct
59 Correct 112 ms 12768 KB Output is correct
60 Correct 397 ms 49440 KB Output is correct
61 Correct 434 ms 48096 KB Output is correct
62 Correct 409 ms 50980 KB Output is correct
63 Correct 490 ms 51616 KB Output is correct
64 Correct 1 ms 724 KB Output is correct
65 Correct 1 ms 852 KB Output is correct
66 Correct 1 ms 852 KB Output is correct
67 Correct 1 ms 708 KB Output is correct
68 Correct 1 ms 852 KB Output is correct
69 Correct 1 ms 980 KB Output is correct
70 Correct 2 ms 980 KB Output is correct
71 Correct 1 ms 980 KB Output is correct
72 Correct 1 ms 832 KB Output is correct
73 Correct 1 ms 980 KB Output is correct
74 Correct 77 ms 41036 KB Output is correct
75 Correct 53 ms 45356 KB Output is correct
76 Correct 54 ms 45244 KB Output is correct
77 Correct 60 ms 45372 KB Output is correct
78 Correct 59 ms 13116 KB Output is correct
79 Correct 43 ms 11452 KB Output is correct
80 Correct 62 ms 33960 KB Output is correct
81 Correct 78 ms 49840 KB Output is correct
82 Correct 85 ms 51120 KB Output is correct
83 Correct 93 ms 52240 KB Output is correct
84 Correct 50 ms 45980 KB Output is correct
85 Correct 88 ms 50800 KB Output is correct
86 Correct 64 ms 16960 KB Output is correct
87 Correct 364 ms 50064 KB Output is correct
88 Correct 314 ms 50080 KB Output is correct
89 Correct 452 ms 47380 KB Output is correct
90 Correct 158 ms 16872 KB Output is correct
91 Correct 188 ms 19080 KB Output is correct
92 Correct 334 ms 38732 KB Output is correct
93 Correct 321 ms 54320 KB Output is correct
94 Correct 505 ms 55444 KB Output is correct
95 Correct 510 ms 56112 KB Output is correct
96 Correct 483 ms 50736 KB Output is correct
97 Correct 503 ms 53376 KB Output is correct