結果

問題 No.3810 Binary Shortest Path Query
コンテスト
ユーザー 👑 Nachia
提出日時 2026-11-20 21:45:27
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,735 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 739 ms
コンパイル使用メモリ 113,932 KB
実行使用メモリ 1,304,292 KB
最終ジャッジ日時 2026-11-20 21:45:39
合計ジャッジ時間 9,269 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23 WA * 2 MLE * 2 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }

void testcase(){
  ll N, M, Q; cin >> N >> M >> Q;
  V<ll> S(N); REP(i,N) cin >> S[i];

  ll dist_lim = *max_element(S.begin(), S.end()) * 2;
  V<tuple<ll,ll,ll>> edges;

  ll edge_weight_lim = dist_lim;
  REP(i,M){
    ll u,v,w; cin >> u >> v >> w; u--; v--;
    edge_weight_lim /= 2;
    if(w <= edge_weight_lim){
      edges.push_back({u,v,w<<(i+1)});
    }
  }

  V<ll> X;
  for(auto [u,v,w] : edges) X.push_back(u);
  for(auto [u,v,w] : edges) X.push_back(v);
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  auto xat = [&](ll x) -> ll {
    if(!binary_search(X.begin(), X.end(), x)) return -1ll;
    return lower_bound(X.begin(), X.end(), x) - X.begin();
  };

  ll K = X.size();
  V<V<ll>> D(K, V<ll>(K, dist_lim));
  REP(i,K) D[i][i] = 0;
  for(auto [u,v,w] : edges) chmin(D[xat(u)][xat(v)], w);
  REP(j,K) REP(i,K) REP(k,K) chmin(D[i][k], D[i][j] + D[j][k]);

  REP(k,edges.size()) for(auto [u,v,w] : edges){
    chmin(S[v], S[u] + w);
    chmin(S[u], S[v] + w);
  }

  REP(qi,Q){
    ll a, b; cin >> a >> b; a--; b--;
    ll ans = S[a] + S[b];
    if(xat(a) >= 0 && xat(b) >= 0){
      chmin(ans, D[xat(a)][xat(b)]);
    }
    cout << ans << "\n";
  }
}

int main(){
  cin.tie(0)->sync_with_stdio(0);
  testcase();
  return 0;
}
0