結果
| 問題 | No.17 2つの地点に泊まりたい |
| コンテスト | |
| ユーザー |
hogeover30
|
| 提出日時 | 2015-02-04 00:51:58 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 759 bytes |
| 記録 | |
| コンパイル時間 | 1,369 ms |
| コンパイル使用メモリ | 173,300 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-03-08 16:01:17 |
| 合計ジャッジ時間 | 1,985 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
const int inf=1<<23;
int n, m;
while (cin>>n) {
vector<int> s(n);
for(int& v: s) cin>>v;
cin>>m;
vector<vector<int>> cost(n, vector<int>(n, inf));
while (m--) {
int a, b, c;
cin>>a>>b>>c;
cost[a][b]=cost[b][a]=c;
}
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
rep(i, n) cost[i][i]=0;
rep(k, n) rep(i, n) rep(j, n)
cost[i][j]=min(cost[i][j], cost[i][k]+cost[k][j]);
int res=inf;
REP(i,1,n-1) REP(j,1,n-1) if (i!=j)
res=min(res, cost[0][i]+s[i]+cost[i][j]+s[j]+cost[j][n-1]);
cout<<res<<endl;
}
}
hogeover30