제출 #1359283

#제출 시각아이디문제언어결과실행 시간메모리
1359283tuncay_pashaCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
393 ms64928 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pasha ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) begin(v), end(v)
using namespace std;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

constexpr int N = 1e+5 + 5, oo = 2e+18;

vector<pair<int, int>> adj[N];
vector<pair<int, int>> dag[N];
int dist[N];
int par[N];
bool used[N];
int dp[N];
bool h = false;
int s, t;
int a, b;
map<pair<int, int>, bool> mark;

void dijkstra(int a) {
  priority_queue<pair<int, int>> pq;
  dist[a] = 0;
  pq.push({0, a});
  while (!pq.empty()) {
    auto [d, u] = pq.top();
    d = -d;
    pq.pop();
    if (dist[u] < d) {
      continue;
    }
    for (auto &[v, w] : (!h ? adj[u] : dag[u])) {
      if (dist[u] + w < dist[v]) {
        dist[v] = dist[u] + w;
        par[v] = u;
        pq.push({-dist[v], v});
      }
    }
  }
}
void dfs1(int u) {
  // cout << u << ' ';
  if (u == b) return;
  used[u] = true;
  for (auto &[v, w] : adj[u]) {
    if (used[v]) continue;
    if (!mark[{u, v}]) mark[{u, v}] = true;
    dfs1(v);
  }
}
void _() {
  int n, m; cin >> n >> m;
  cin >> s >> t;
  cin >> a >> b;
  vector<array<int, 3>> e;
  for (int i = 0; i < m; ++i) {
    int u, v, w; cin >> u >> v >> w;
    e.pb({u, v, w});
    adj[u].pb({v, w}), adj[v].pb({u, w});
  }
  for (int i = 1; i <= n; ++i) {
    par[i] = -1;
    dist[i] = oo;
  }
  dijkstra(s);
  vector<int> f;
  int node = t;
  while (par[node] != -1) {
    f.pb(node);
    node = par[node];
  }
  f.pb(s);
  reverse(all(f));
  map<pair<int, int>, bool> special;
  for (int i = 1; i < f.size(); ++i) {
    mark[{f[i - 1], f[i]}] = true;
    special[{f[i - 1], f[i]}] = true;
    special[{f[i], f[i - 1]}] = true;
  }
  dfs1(s);
  // return;
  for (auto &[u, v, w] : e) {
    if (special[{u, v}]) w = 0;
    if (mark[{u, v}]) dag[u].pb({v, w});
    else dag[v].pb({u, w});
  }
  for (int i = 1; i <= n; ++i) {
    par[i] = -1;
    dist[i] = oo;
  }
  h = true;
  dijkstra(a);
  cout << dist[b] << '\n';
}

signed main() {
  pasha
  int t = 1;
  // cin >> t;
  for (int cs = 1; cs <= t; ++cs) {
    _();
    // cout << '\n';
  }
} 
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…