結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-06-09 19:37:08 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,043 bytes | 
| コンパイル時間 | 2,152 ms | 
| コンパイル使用メモリ | 199,868 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-06-09 19:37:12 | 
| 合計ジャッジ時間 | 3,349 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,i; cin>>N;
    vector<ll> cost(N);
    for(i=0;i<N;++i) cin>>cost[i];
    const ll INF = 1e15;
    vector<vector<ll>> dist(N, vector<ll>(N,INF));
    for(int i=0;i<N;++i) dist[i][i]=0;
    int M;cin>>M;
    for(i=0;i<M;++i){
        int a,b; ll c; cin>>a>>b>>c;
        dist[a][b]=min(dist[a][b], c);
        dist[b][a]=min(dist[b][a],c);
    }
    for(int k=0;k<N;++k){
        for(int i=0;i<N;++i){
            for(int j=0;j<N;++j){
                if(dist[i][k]==INF || dist[k][j]==INF) continue;
                dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    // print__(dist, cost);
    ll ANS=INF;
    for(int i=1;i+1<N;++i) for(int j=1;j+1<N;++j) if(i!=j){
        if(dist[0][i]==INF || dist[i][j]==INF || dist[j][N-1]==INF) continue;
        ANS=min(ANS,dist[0][i]+cost[i]+dist[i][j]+cost[j]+dist[j][N-1]);
    }
    cout<<ANS<<endl;
    return 0;
}
            
            
            
        