結果
| 問題 | No.3810 Binary Shortest Path Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-20 21:55:10 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,125 bytes |
| 記録 | |
| コンパイル時間 | 1,697 ms |
| コンパイル使用メモリ | 236,500 KB |
| 実行使用メモリ | 9,868 KB |
| 最終ジャッジ日時 | 2026-11-20 21:55:25 |
| 合計ジャッジ時間 | 9,555 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 2 |
ソースコード
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,Q; cin >> N >> M >> Q;
vector<long long> S(N);
for(auto &s : S) cin >> s;
vector<int> P;
vector<tuple<int,int,long long>> edge;
for(int i=0; i<M; i++){
long long u,v,w; cin >> u >> v >> w,u--,v--;
if(i > 62) continue;
for(int k=0; k<=i; k++){
w += w;
if(w >= S.at(u)+S.at(v)) break;
}
if(w >= S.at(u)+S.at(v)) continue;
P.push_back(u),P.push_back(v);
edge.push_back({u,v,w});
}
sort(P.begin(),P.end());
P.erase((unique(P.begin(),P.end())),P.end());
int n = P.size();
vector<vector<long long>> dist(n,vector<long long>(n));
for(int i=0; i<n; i++) for(int k=0; k<n; k++){
if(i == k) dist.at(i).at(k) = 0;
else dist.at(i).at(k) = S.at(P.at(i))+S.at(P.at(k));
}
for(auto [u,v,w] : edge){
u = lower_bound(P.begin(),P.end(),u)-P.begin();
v = lower_bound(P.begin(),P.end(),v)-P.begin();
dist.at(u).at(v) = min(dist.at(u).at(v),w);
dist.at(v).at(u) = min(dist.at(v).at(u),w);
}
for(int i=0; i<n; i++) for(int k=0; k<n; k++) for(int l=0; l<n; l++){
dist.at(k).at(l) = min(dist.at(k).at(l),dist.at(k).at(i)+dist.at(i).at(l));
}
P.push_back(N);
while(Q--){
int a,b; cin >> a >> b,a--,b--;
int pa = lower_bound(P.begin(),P.end(),a)-P.begin();
int pb = lower_bound(P.begin(),P.end(),b)-P.begin();
if(P.at(pa) != a && P.at(pb) != b){
cout << S.at(a)+S.at(b) << "\n";
continue;
}
if(P.at(pb) == b) swap(a,b),swap(pa,pb);
if(P.at(pb) == b){
cout << dist.at(pa).at(pb) << "\n";
continue;
}
else{
long long answer = S.at(a)+S.at(b);
for(int i=0; i<n; i++){
int pos = P.at(i);
answer = min(answer,dist.at(pa).at(i)+S.at(pos)+S.at(b));
}
cout << answer << "\n";
}
}
}