제출 #1324237

#제출 시각아이디문제언어결과실행 시간메모리
1324237reyleighCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
539 ms36124 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll inf = 1e17;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m; cin >> n >> m;
  int s, t, u, v; cin >> s >> t >> u >> v;
  vector<pair<int, int>> g[n + 1];
  for (int i = 1; i <= m; i++) {
    int a, b, c; cin >> a >> b >> c;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  vector<int> path(n + 1, 0);
  vector<ll> st(n + 1, inf);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
  pq.push({0, s});
  st[s] = 0;
  while (!pq.empty()) {
    auto [w, a] = pq.top(); pq.pop();
    for (auto [b, c] : g[a]) {
      if (1ll * w + c < st[b]) {
        st[b] = 1ll * w + c;
        pq.push({1ll * w + c, b});
        path[b] = a;
      }
    }
  }
  map<pair<int, int>, bool> mp;
  for (int i = t; path[i]; i = path[i]) {
    mp[{i, path[i]}] = 1;
    mp[{path[i], i}] = 1;
  }
  for (int i = 1; i <= n; i++) st[i] = inf;
  pq.push({0, u});
  st[u] = 0;
  while (!pq.empty()) {
    auto [w, a] = pq.top(); pq.pop();
    for (auto [b, c] : g[a]) {
      if (mp[{a, b}] or mp[{b, a}]) c = 0;
      if (1ll * w + c < st[b]) {
        st[b] = 1ll * w + c;
        pq.push({1ll * w + c, b});
      }
    }
  }
  cout << st[v] << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...