Submission #550994

# Submission time Handle Problem Language Result Execution time Memory
550994 2022-04-19T17:04:17 Z hoanghq2004 Swapping Cities (APIO20_swap) C++14
0 / 100
2000 ms 9460 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 par[N], sz[N], 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 getMinimumFuelCapacity(int, int)':
swap.cpp:45:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for (auto [w, u, v]: g) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 34 ms 5412 KB Output is correct
10 Correct 46 ms 6144 KB Output is correct
11 Correct 44 ms 6140 KB Output is correct
12 Correct 47 ms 6460 KB Output is correct
13 Correct 45 ms 6448 KB Output is correct
14 Execution timed out 2066 ms 5816 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Execution timed out 2086 ms 9460 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 34 ms 5412 KB Output is correct
10 Correct 46 ms 6144 KB Output is correct
11 Correct 44 ms 6140 KB Output is correct
12 Correct 47 ms 6460 KB Output is correct
13 Correct 45 ms 6448 KB Output is correct
14 Execution timed out 2066 ms 5816 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -