Submission #964092

# Submission time Handle Problem Language Result Execution time Memory
964092 2024-04-16T10:09:20 Z efedmrlr Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 17420 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "swap.h"
#include <bits/stdc++.h>

using namespace std;


#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m;

vector<vector<array<int, 2> > > adj;
vector<array<int,3> > edges;
void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    adj.assign(N + 1, vector<array<int,2> >());
    n = N; m = M;
    edges.resize(M);
    for(int i = 0; i < m; i++) {
      adj[U[i]].pb({V[i], W[i]});
      adj[V[i]].pb({U[i], W[i]});
      edges[i] = {U[i], V[i], W[i]};
    }

}

void dijkstra(int src, vector<int> &sp, vector<vector<array<int,2> > > &ad, vector<int> &pr) {
  priority_queue<array<int,2>, vector<array<int,2> >, greater<array<int,2> > > pq;
  sp.assign(n, INF);
  pr.assign(n, -1);
  pq.push({0, src});
  while(pq.size()) {
    auto cur = pq.top();
    pq.pop();
    if(sp[cur[1]] != INF) {
      continue;
    }
    // cout << cur[1] << " :" << cur[0] << "\n";
    sp[cur[1]] = cur[0];
    for(auto c : ad[cur[1]]) {
      if(sp[c[0]] != INF) continue;
      pq.push({max(cur[0] , c[1]), c[0]});
      pr[c[0]] = cur[1];

    }
  }
}

int getMinimumFuelCapacity(int X, int Y) {
  vector<int> sp, pr;
  dijkstra(X, sp, adj, pr);
  int cost = sp[Y];
  int ext = INF;
  
  
  int x = Y;
  vector<vector<array<int,2> > > tmp(adj);
  int cost2 = sp[Y];
  while(x != X) {
    // cout << x << " " << pr[x] << endl;
    assert(pr[x] != -1);
    for(auto itr = tmp[x].begin(); itr != tmp[x].end(); itr++) {
      if((*itr)[0] == pr[x]) {
        tmp[x].erase(itr);
        break;
      }
    }
    for(auto itr = tmp[pr[x]].begin(); itr != tmp[pr[x]].end(); itr++) {
      if((*itr)[0] == x) {
        tmp[pr[x]].erase(itr);
        break;
      }
    }
    x = pr[x];

  }
  x = pr[Y];
  while(x != X) {
    for(auto c : tmp[x]) {
      ext = min(ext, c[1]);
    }
    x = pr[x];
  }
    cost = max(cost, ext);
  dijkstra(X, sp, tmp, pr);
  cost2 = max(cost2, sp[Y]);
  if(min(cost2, cost) == INF) return -1; 
  // cout << endl;
  return min(cost2, cost);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 61 ms 11644 KB Output is correct
10 Correct 103 ms 13960 KB Output is correct
11 Correct 105 ms 13740 KB Output is correct
12 Correct 110 ms 14476 KB Output is correct
13 Correct 124 ms 14596 KB Output is correct
14 Execution timed out 2047 ms 11656 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2054 ms 17420 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 848 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 1 ms 444 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 388 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 61 ms 11644 KB Output is correct
11 Correct 103 ms 13960 KB Output is correct
12 Correct 105 ms 13740 KB Output is correct
13 Correct 110 ms 14476 KB Output is correct
14 Correct 124 ms 14596 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 848 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 1 ms 444 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 61 ms 11644 KB Output is correct
10 Correct 103 ms 13960 KB Output is correct
11 Correct 105 ms 13740 KB Output is correct
12 Correct 110 ms 14476 KB Output is correct
13 Correct 124 ms 14596 KB Output is correct
14 Execution timed out 2047 ms 11656 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 388 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 61 ms 11644 KB Output is correct
11 Correct 103 ms 13960 KB Output is correct
12 Correct 105 ms 13740 KB Output is correct
13 Correct 110 ms 14476 KB Output is correct
14 Correct 124 ms 14596 KB Output is correct
15 Execution timed out 2047 ms 11656 KB Time limit exceeded
16 Halted 0 ms 0 KB -