結果
問題 |
No.17 2つの地点に泊まりたい
|
ユーザー |
![]() |
提出日時 | 2021-07-14 01:42:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 934 bytes |
コンパイル時間 | 2,046 ms |
コンパイル使用メモリ | 171,924 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 22:35:52 |
合計ジャッジ時間 | 2,644 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; using Graph=vector<vector<int>>; #define MAX 1000000 #define MOD 1000000009 //#define MOD 998244353 //#define INF 1000000000 #define INF 1000000000000000000 int main(){ int N; cin>>N; vector<ll> S(N); for(int i=0;i<N;i++){ cin>>S[i]; } vector<vector<ll>> dist(N,vector<ll>(N,INF)); int M; cin>>M; for(int 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++){ dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]); } } } ll ans=INF; for(int i=1;i<N-1;i++){ for(int j=1;j<N-1;j++){ if(i==j){ continue; } ans=min(ans,dist[0][i]+dist[i][j]+dist[j][N-1]+S[i]+S[j]); } } cout<<ans<<endl; }