제출 #701784

#제출 시각아이디문제언어결과실행 시간메모리
701784mychecksedadCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
287 ms43072 KiB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;
 
 
int n, m, s, t, x, y;
ll d[N];
vector<array<ll, 3>> g[N];
vector<bool> vis;
vector<pair<int, int>> good;
 
void solve(){
  cin >> n >> m >> s >> t >> x >> y;
  for(int i = 0; i < m; ++i){
    int u, v, w; cin >> u >> v >> w;
    g[u].pb({v, w, i});
    g[v].pb({u, w, i});
  }
  vis.resize(n + 1);
  good.resize(m);
  priority_queue<pair<ll, int>> q;
  q.push({0, s});
  for(int i = 1; i <= n; ++i) d[i] = i == s ? 0 : LONG_LONG_MAX;
  while(!q.empty()){
    int v = q.top().second; q.pop();
    if(vis[v]) continue;
    vis[v] = 1;
    for(auto U: g[v]){
      int u = U[0], w = U[1];
      if(!vis[u] && d[u] > d[v] + w){
        d[u] = d[v] + w;
        q.push({-d[u], u});
      }
    }
  }
  queue<int> Q;
  Q.push(t);
  fill(all(vis), 0);
  vis[t] = 1;
  while(!Q.empty()){
    int v = Q.front(); Q.pop();
    for(auto U: g[v]){
      int u = U[0], w = U[1];
      if(!vis[u] && d[u] == d[v] - w){
        vis[u] = 1;
        good[U[2]] = {v, u};
        Q.push(u);
      }
    }
  }
  for(int i = 1; i <= n; ++i) d[i] = LONG_LONG_MAX;
  d[x] = 0;
  q.push({0, x});
  fill(all(vis), 0);
  while(!q.empty()){
    int v = q.top().second; q.pop();
    if(vis[v]) continue;
    vis[v] = 1;
    for(auto U: g[v]){
      int u = U[0], w = U[1];
      if(good[U[2]].first == v && good[U[2]].second == u) w = 0;
      if(!vis[u] && d[u] > d[v] + w){
        d[u] = d[v] + w;
        q.push({-d[u], u});
      }
    }
  }
  ll ans = d[y];
  for(int i = 1; i <= n; ++i) d[i] = LONG_LONG_MAX;
  d[x] = 0;
  q.push({0, x});
  fill(all(vis), 0);
  while(!q.empty()){
    int v = q.top().second; q.pop();
    if(vis[v]) continue;
    vis[v] = 1;
    for(auto U: g[v]){
      int u = U[0], w = U[1];
      if(good[U[2]].first == u && good[U[2]].second == v) w = 0;
      if(!vis[u] && d[u] > d[v] + w){
        d[u] = d[v] + w;
        q.push({-d[u], u});
      }
    }
  }
  cout << min(ans, d[y]);
}
 
 
int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:99:14: warning: unused variable 'aa' [-Wunused-variable]
   99 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...