Submission #742199

# Submission time Handle Problem Language Result Execution time Memory
742199 2023-05-15T18:45:39 Z 1zaid1 Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int M = 1e5+5;
vector<array<int, 3>> E;
vector<int> node[M];

int n, m;
void init(int _n, int _m, vector<int> U, vector<int> V, vector<int> W) {
    n = _n, m = _m;
    for (int i = 0; i < m; i++) E.push_back({U[i], V[i], W[i]});
    sort(E.begin(), E.end(), [](array<int, 3> a, array<int, 3> b){return a[2] < b[2];});
}

int mn[M], vis[M], p[M], d[M];
void clear() {
    for (int i = 0; i < n; i++) {
        vis[i] = mn[i] = p[i] = d[i] = 0;
        node[i].clear();
    }
}

void dfs(int s, int P) {
    vis[s] = true;
    d[s] = d[P]+1;
    p[s] = P;

    vector<int> c;
    mn[s] = INT_MAX;
    for (int i:node[s]) {
        if (!vis[i]) dfs(i, s), c.push_back(i);
        else if (i != P) mn[s] = min(mn[s], d[i]);
    }

    for (int i:c) mn[s] = min(mn[s], mn[i]);
}

bool check(int a, int b, int X) {
    clear();

    for (int i = 0; i < X; i++) {
        auto [A, B, C] = E[i];
        node[A].push_back(B);
        node[B].push_back(A);
    }

    dfs(a, a);
    int mxD = 0;
    int x = p[b];
    if (!vis[b]) return 0;

    while (x != a) mxD = max(mxD, (int)node[x].size()), x = p[x];
    return mxD > 2 || mn[b] == 1;
} 

int solve(int a, int b) {
    int x = 0, p2 = (1<<18);
    while (p2 /= 2) {
        if (!check(a, b, x+p2)) x += p2;
    }

    if (x==m) return -1;
    return E[x][2];
}

int getMinimumFuelCapacity(int X, int Y) {
    return solve(X, Y);
}

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;
}

Compilation message

/usr/bin/ld: /tmp/ccorFyKp.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccX7aaUn.o:swap.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status