Submission #550995

# Submission time Handle Problem Language Result Execution time Memory
550995 2022-04-19T17:06:00 Z hoanghq2004 Swapping Cities (APIO20_swap) C++14
0 / 100
2000 ms 6124 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) {
    n = N;
    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:46:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     for (auto [w, u, v]: g) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 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 340 KB Output is correct
9 Correct 35 ms 3792 KB Output is correct
10 Correct 48 ms 4192 KB Output is correct
11 Correct 49 ms 4140 KB Output is correct
12 Correct 56 ms 4300 KB Output is correct
13 Correct 49 ms 4508 KB Output is correct
14 Execution timed out 2084 ms 3908 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 0 ms 212 KB Output is correct
3 Execution timed out 2070 ms 6124 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 0 ms 212 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 340 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 0 ms 212 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 340 KB Output is correct
9 Correct 35 ms 3792 KB Output is correct
10 Correct 48 ms 4192 KB Output is correct
11 Correct 49 ms 4140 KB Output is correct
12 Correct 56 ms 4300 KB Output is correct
13 Correct 49 ms 4508 KB Output is correct
14 Execution timed out 2084 ms 3908 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 -