結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
kapo
|
| 提出日時 | 2016-05-30 14:55:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 902 bytes |
| コンパイル時間 | 620 ms |
| コンパイル使用メモリ | 59,304 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-07 18:39:01 |
| 合計ジャッジ時間 | 1,667 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 6 |
ソースコード
#include <iostream>
#include <algorithm>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
#define INF 1e9
int main(void)
{
int N, M;
cin >> N;
int S[50];
rep(i,0,N) cin >> S[i];
cin >> M;
int G[50][50];
int from, to, cost;
rep(i,0,N) rep(j,0,N) G[i][j] = INF;
rep(i,0,M) {
cin >> from >> to >> cost;
G[from][to] = min(G[from][to], cost);
G[to][from] = G[from][to];
}
rep(i,0,N) G[i][i] = 0;
rep(k,0,N) rep(i,0,N) rep(j,0,N) {
if(G[i][j] > G[i][k] + G[k][j]) G[i][j] = G[i][k] + G[k][j];
}
// rep(i,0,N) rep(j,0,N) printf("G[%d][%d] = %d\n",i,j,G[i][j]);
int ans = INF;
rep(i,1,N-1) rep(j,1,N-1) {
if(i == j) continue;
if(ans > G[0][i] + G[i][j] + G[j][N-1] + S[i] +S[j]) {
ans = G[0][i] + G[i][j] + G[j][N-1] + S[i] +S[j];
// printf("i=%d j=%d ans=%d\n",i,j,G[0][i] + G[i][j] + G[j][N-1] + S[i] +S[j]);
}
}
cout << ans << endl;
return 0;
}
kapo