Submission #823881

# Submission time Handle Problem Language Result Execution time Memory
823881 2023-08-13T09:28:57 Z abczz Swapping Cities (APIO20_swap) C++14
6 / 100
534 ms 50856 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];
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) {
    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;
      ++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 596 KB Output is correct
5 Correct 1 ms 828 KB Output is correct
6 Correct 1 ms 828 KB Output is correct
7 Correct 1 ms 832 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 42 ms 35356 KB Output is correct
10 Correct 52 ms 43256 KB Output is correct
11 Correct 52 ms 42488 KB Output is correct
12 Correct 55 ms 44844 KB Output is correct
13 Correct 53 ms 45464 KB Output is correct
14 Correct 72 ms 35636 KB Output is correct
15 Correct 459 ms 47464 KB Output is correct
16 Correct 468 ms 46312 KB Output is correct
17 Correct 461 ms 48796 KB Output is correct
18 Correct 504 ms 49424 KB Output is correct
19 Correct 104 ms 12744 KB Output is correct
20 Correct 460 ms 48712 KB Output is correct
21 Correct 428 ms 47356 KB Output is correct
22 Correct 458 ms 50204 KB Output is correct
23 Correct 510 ms 50856 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 Incorrect 534 ms 47776 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 596 KB Output is correct
5 Correct 1 ms 828 KB Output is correct
6 Correct 1 ms 828 KB Output is correct
7 Correct 1 ms 832 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Incorrect 1 ms 832 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 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 596 KB Output is correct
6 Correct 1 ms 828 KB Output is correct
7 Correct 1 ms 828 KB Output is correct
8 Correct 1 ms 832 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 42 ms 35356 KB Output is correct
11 Correct 52 ms 43256 KB Output is correct
12 Correct 52 ms 42488 KB Output is correct
13 Correct 55 ms 44844 KB Output is correct
14 Correct 53 ms 45464 KB Output is correct
15 Incorrect 1 ms 832 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 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 596 KB Output is correct
5 Correct 1 ms 828 KB Output is correct
6 Correct 1 ms 828 KB Output is correct
7 Correct 1 ms 832 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 42 ms 35356 KB Output is correct
10 Correct 52 ms 43256 KB Output is correct
11 Correct 52 ms 42488 KB Output is correct
12 Correct 55 ms 44844 KB Output is correct
13 Correct 53 ms 45464 KB Output is correct
14 Correct 72 ms 35636 KB Output is correct
15 Correct 459 ms 47464 KB Output is correct
16 Correct 468 ms 46312 KB Output is correct
17 Correct 461 ms 48796 KB Output is correct
18 Correct 504 ms 49424 KB Output is correct
19 Incorrect 534 ms 47776 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 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 596 KB Output is correct
6 Correct 1 ms 828 KB Output is correct
7 Correct 1 ms 828 KB Output is correct
8 Correct 1 ms 832 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 42 ms 35356 KB Output is correct
11 Correct 52 ms 43256 KB Output is correct
12 Correct 52 ms 42488 KB Output is correct
13 Correct 55 ms 44844 KB Output is correct
14 Correct 53 ms 45464 KB Output is correct
15 Correct 72 ms 35636 KB Output is correct
16 Correct 459 ms 47464 KB Output is correct
17 Correct 468 ms 46312 KB Output is correct
18 Correct 461 ms 48796 KB Output is correct
19 Correct 504 ms 49424 KB Output is correct
20 Incorrect 534 ms 47776 KB Output isn't correct
21 Halted 0 ms 0 KB -