Submission #1036811

# Submission time Handle Problem Language Result Execution time Memory
1036811 2024-07-27T17:28:36 Z juicy Olympic Bus (JOI20_ho_t4) C++17
0 / 100
82 ms 2988 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 205, M = 5e4 + 5;
const int inf = 1e9;

int n, m;
int pr[N], w[M], d[2][N];
bool spec[M];
vector<array<int, 2>> g[N];
array<int, 3> edges[M];

void dijkstra(int s, int *d) {
  using T = array<int, 2>;
  priority_queue<T, vector<T>, greater<T>> pq;
  fill(d + 1, d + n + 1, inf);
  fill(pr + 1, pr + n + 1, 0);
  pq.push({d[s] = 0, s});
  while (pq.size()) {
    auto [c, u] = pq.top(); pq.pop();
    if (c != d[u]) {
      continue;
    }
    for (auto [v, id] : g[u]) {
      if (d[v] > d[u] + w[id]) {
        pr[v] = id;
        pq.push({d[v] = d[u] + w[id], v});
      }
    }
  }
}

void mark() {
  for (int i = 1; i <= n; ++i) {
    spec[pr[i]] = 1;
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v, c; cin >> u >> v >> w[i] >> c;
    edges[i] = {u, v, c};
    g[u].push_back({v, i});
  }
  dijkstra(1, d[0]);
  mark();
  dijkstra(n, d[1]);
  mark();
  auto del = [&](int u, array<int, 2> x) {
    for (auto &v : g[u]) {
      if (v == x) {
        swap(v, g[u].back());
        g[u].pop_back();
        break;
      }
    }
  };
  auto add = [&](int u, array<int, 2> x) {
    g[u].push_back(x);
  };
  int res = 2 * inf, ans = res;
  if (d[0][n] != inf && d[1][1] != inf) {
    ans = d[0][n] + d[1][1];
  }
  for (int i = 1; i <= m; ++i) {
    if (spec[i]) {
      auto [u, v, c] = edges[i];
      del(u, {v, i});
      add(v, {u, i});
      dijkstra(1, d[0]);
      dijkstra(n, d[1]);
      if (d[0][n] != inf && d[1][1] != inf) {
        res = min(res, d[0][n] + d[1][1] + c);
      }
      del(v, {u, i});
      add(u, {v, i});
    } else {
      res = min(res, ans);
    }
  }
  cout << (res != 2 * inf ? res : -1);
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 10 ms 348 KB Output is correct
4 Correct 12 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 80 ms 2988 KB Output is correct
2 Incorrect 82 ms 2896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 48 ms 2140 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 55 ms 2860 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 19 ms 2888 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 10 ms 348 KB Output is correct
4 Correct 12 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -