제출 #1339613

#제출 시각아이디문제언어결과실행 시간메모리
1339613repmannCommuter Pass (JOI18_commuter_pass)C++20
15 / 100
2094 ms16132 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int N, M;
ll DIST[5][100001], sol;
vector <pair <int, int>> VG[100001];
void Dijkstra(int node, ll dist, int i)
{
  fill(DIST[i] + 1, DIST[i] + N + 1, 1e18);
  DIST[i][node] = dist;
  if(i == 2)
  {
    for(int j = 1; j <= N; j++) DIST[3][j] = DIST[0][j];
    for(int j = 1; j <= N; j++) DIST[4][j] = DIST[1][j];
  }
  priority_queue <pair <ll, int>> H;
  H.push({-dist, node});
  while(H.size())
  {
    node = H.top().second;
    dist = -H.top().first;
    H.pop();
    if(dist != DIST[i][node]) continue;
    if(i == 2)
    {
      for(pair <int, int> p : VG[node])
      {
        if((DIST[i][node] - p.first) != DIST[i][p.second]) continue;
        DIST[3][node] = min(DIST[3][p.second], DIST[3][node]);
        DIST[4][node] = min(DIST[4][p.second], DIST[4][node]);
      }
    }
    for(pair <int, int> p : VG[node])
    {
      if((DIST[i][node] + p.first) >= DIST[i][p.second]) continue;
      DIST[i][p.second] = DIST[i][node] + p.first;
      H.push({-DIST[i][p.second], p.second});
    }
  }
  return;
}
void DFS(int node)
{
  sol = min({DIST[0][node] + DIST[4][node], DIST[1][node] + DIST[3][node], sol});
  for(pair <int, int> p : VG[node])
  {
    if((DIST[2][node] - p.first) == DIST[2][p.second]) DFS(p.second);
  }
  return;
}
int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> M;
  int s, t, s1, t1, u, v, w;
  cin >> s >> t >> s1 >> t1;
  for(int i = 1; i <= M; i++)
  {
    cin >> u >> v >> w;
    VG[u].push_back({w, v});
    VG[v].push_back({w, u});
  }
  Dijkstra(s1, 0, 0);
  Dijkstra(t1, 0, 1);
  Dijkstra(s, 0, 2);
  sol = DIST[0][t1];
  DFS(t);
  cout << sol << '\n';

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...