結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
Kutimoti_T
|
| 提出日時 | 2017-12-18 08:00:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,057 bytes |
| コンパイル時間 | 542 ms |
| コンパイル使用メモリ | 67,380 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 01:42:45 |
| 合計ジャッジ時間 | 1,236 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define FOR(i, s, e) for (int i = (s); i <= (e); i++)
#define INF 10000000;
int N;
int stay[50];
int M;
int dp[55][55];
int main()
{
FOR(i, 0, 54)
{
FOR(j, 0, 54)
{
dp[i][j] = INF
}
}
cin >> N;
FOR(i, 0, N - 1)
{
cin >> stay[i];
}
cin >> M;
int a, b, c;
FOR(i, 0, M - 1)
{
cin >> a >> b >> c;
dp[a][b] = c;
dp[b][a] = c;
}
FOR(i,0,N - 1)
{
FOR(j,0,N - 1)
{
FOR(k,0,N - 1)
{
dp[j][k] = min(dp[j][k],dp[j][i] + dp[i][k]);
}
}
}
int res = INF;
FOR(i,1,N - 2)
{
FOR(j,1,N - 2)
{
if(i != j)
{
res = min(res,dp[0][i] + stay[i] + dp[i][j] + stay[j] + dp[j][N - 1]);
}
}
}
cout << res << endl;
return 0;
}
Kutimoti_T