結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2015-07-19 16:54:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 886 ms |
コンパイル使用メモリ | 81,096 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 01:25:17 |
合計ジャッジ時間 | 1,531 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include<sstream> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) #define indexOf(v,x) (find(all(v),x)-v.begin()) int main(){ int dist[50][50],s[50],n; cin>>n; rep(i,n){ cin>>s[i]; } fill(dist[0],dist[50],INF); rep(i,n)dist[i][i]=0; int m; cin>>m; rep(i,m){ int a,b,c; cin>>a>>b>>c; dist[a][b]=dist[b][a]=c; } rep(k,n)rep(i,n)rep(j,n)dist[i][j]=min(dist[i][j],dist[i][k]+dist[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,s[i]+s[j]+dist[0][i]+dist[i][j]+dist[j][n-1]); } cout<<ans<<endl; return 0; }