답안 #1036806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036806 2024-07-27T17:25:49 Z juicy Olympic Bus (JOI20_ho_t4) C++17
0 / 100
91 ms 2984 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;
  if (d[0][n] != inf && d[1][1] != inf) {
    res = 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});
    }
  }
  cout << (res != 2 * inf ? res : -1);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 10 ms 528 KB Output is correct
4 Correct 12 ms 344 KB Output is correct
5 Correct 1 ms 344 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 532 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 2984 KB Output is correct
2 Incorrect 91 ms 2908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 45 ms 2304 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 69 ms 2876 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 20 ms 2652 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 10 ms 528 KB Output is correct
4 Correct 12 ms 344 KB Output is correct
5 Correct 1 ms 344 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 532 KB Output isn't correct
10 Halted 0 ms 0 KB -