답안 #550997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550997 2022-04-19T17:08:08 Z hoanghq2004 자매 도시 (APIO20_swap) C++14
0 / 100
2000 ms 6244 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) {
    ++deg[u], ++deg[v];
    int ru = Find(u), rv = Find(v);
    if (ru != rv) {
        if (sz[ru] < sz[rv]) swap(ru, rv);
        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:47:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     for (auto [w, u, v]: g) {
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 36 ms 3796 KB Output is correct
10 Correct 50 ms 4184 KB Output is correct
11 Correct 54 ms 4172 KB Output is correct
12 Correct 56 ms 4324 KB Output is correct
13 Correct 51 ms 4328 KB Output is correct
14 Execution timed out 2085 ms 3900 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 2085 ms 6244 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 36 ms 3796 KB Output is correct
10 Correct 50 ms 4184 KB Output is correct
11 Correct 54 ms 4172 KB Output is correct
12 Correct 56 ms 4324 KB Output is correct
13 Correct 51 ms 4328 KB Output is correct
14 Execution timed out 2085 ms 3900 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -