結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2018-06-03 18:31:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 875 bytes |
コンパイル時間 | 2,960 ms |
コンパイル使用メモリ | 158,048 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-15 04:08:20 |
合計ジャッジ時間 | 2,298 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> P; const ll MOD=1000000007; const ll INF=10000010; const ll LINF=4000000000000000010LL; const int MAX=310; const double EPS=1e-9; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int main(){ int n;cin>>n; int s[51]; int d[51][51]; for(int i=0;i<n;i++){ cin>>s[i]; } int m;cin>>m; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ d[i][j]=INF; if(i==j)d[i][j]=0; } } for(int i=0;i<m;i++){ int a,b,c;cin>>a>>b>>c; d[a][b]=min(d[a][b],c); d[b][a]=min(d[b][a],c); } for(int k=0;k<n;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ d[i][j]=min(d[i][j],d[i][k]+d[k][j]); } } } int 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,d[0][i]+d[i][j]+d[j][n-1]+s[i]+s[j]); } } cout<<ans<<endl; return 0; }