Submission #550993

# Submission time Handle Problem Language Result Execution time Memory
550993 2022-04-19T17:03:26 Z hoanghq2004 Swapping Cities (APIO20_swap) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define Submit
#ifdef Submit
#include "swap.h"

#endif // Submit

using namespace __gnu_pbds;
using namespace std;

const int N = 1e5 + 10;

int n;
vector <tuple <int, int, int> > g;
int deg[N];

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    for (int i = 0; i < M; ++i)
        g.push_back({W[i], U[i], V[i]});
    sort(g.begin(), g.end());
}

int ok[N];
int Find(int u) {
    return (u == par[u] ? u : par[u] = Find(par[u]));
}

void Union(int u, int v) {
    int ru = Find(u), rv = Find(v);
    if (ru != rv) {
        if (sz[ru] < sz[rv]) swap(u, v);
        par[rv] = ru;
        sz[ru] += rv;
        ok[ru] |= ok[rv];
    }
    if (deg[u] > 2 || deg[v] > 2) ok[ru] = 1;
}

int getMinimumFuelCapacity(int X, int Y) {
    for (int i = 0; i < n; ++i) par[i] = i, deg[i] = 0, ok[i] = 0, sz[i] = 1;
    for (auto [w, u, v]: g) {
        Union(u, v);
        if (Find(X) == Find(Y) && ok[Find(X)]) return w;
    }
    return -1;
}


#ifndef Submit

int main() {
  int N, M;
  assert(2 == scanf("%d %d", &N, &M));

  std::vector<int> U(M), V(M), W(M);
  for (int i = 0; i < M; ++i) {
    assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
  }

  int Q;
  assert(1 == scanf("%d", &Q));

  std::vector<int> X(Q), Y(Q);
  for (int i = 0; i < Q; ++i) {
    assert(2 == scanf("%d %d", &X[i], &Y[i]));
  }

  init(N, M, U, V, W);

  std::vector<int> minimum_fuel_capacities(Q);
  for (int i = 0; i < Q; ++i) {
    minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
  }

  for (int i = 0; i < Q; ++i) {
    printf("%d\n", minimum_fuel_capacities[i]);
  }

  return 0;
}

#endif // Submit

Compilation message

swap.cpp: In function 'int Find(int)':
swap.cpp:29:18: error: 'par' was not declared in this scope
   29 |     return (u == par[u] ? u : par[u] = Find(par[u]));
      |                  ^~~
swap.cpp: In function 'void Union(int, int)':
swap.cpp:35:13: error: 'sz' was not declared in this scope
   35 |         if (sz[ru] < sz[rv]) swap(u, v);
      |             ^~
swap.cpp:36:9: error: 'par' was not declared in this scope
   36 |         par[rv] = ru;
      |         ^~~
swap.cpp:37:9: error: 'sz' was not declared in this scope
   37 |         sz[ru] += rv;
      |         ^~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:44:33: error: 'par' was not declared in this scope
   44 |     for (int i = 0; i < n; ++i) par[i] = i, deg[i] = 0, ok[i] = 0, sz[i] = 1;
      |                                 ^~~
swap.cpp:44:68: error: 'sz' was not declared in this scope
   44 |     for (int i = 0; i < n; ++i) par[i] = i, deg[i] = 0, ok[i] = 0, sz[i] = 1;
      |                                                                    ^~
swap.cpp:45:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for (auto [w, u, v]: g) {
      |               ^