結果
| 問題 | No.17 2つの地点に泊まりたい |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-08 23:23:59 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| + 574µs | |
| コード長 | 740 bytes |
| 記録 | |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 60,800 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-17 04:12:40 |
| 合計ジャッジ時間 | 1,616 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <vector>
#include <cstdio>
using namespace std;
int main(){
int n,m;
scanf("%d",&n);
vector<int>cost(n);
vector<vector<long long> >dist(n);
for(int i=0;i<n;i++){
scanf("%d",&cost[i]);
dist[i].resize(n);
for(int j=0;j<n;j++)dist[i][j]=1LL<<61;
dist[i][i]=0;
}
scanf("%d",&m);
for(int i=0;i<m;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
dist[a][b]=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][j]>dist[i][k]+dist[k][j])dist[i][j]=dist[i][k]+dist[k][j];
long long ma=1LL<<61;
for(int i=1;i<n-1;i++)for(int j=1;j<n-1;j++)
if(i!=j&&ma>dist[0][i]+cost[i]+dist[i][j]+cost[j]+dist[j][n-1])ma=dist[0][i]+cost[i]+dist[i][j]+cost[j]+dist[j][n-1];
printf("%lld\n",ma);
}