結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2020-06-07 20:25:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,049 bytes |
コンパイル時間 | 2,457 ms |
コンパイル使用メモリ | 196,940 KB |
最終ジャッジ日時 | 2025-01-10 23:57:04 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> S(N); for (int i = 0; i < N; i++) { cin >> S[i]; } int M; cin >> M; vector<vector<int>> G(N, vector<int>(N, INF)); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; G[a][b] = G[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 (G[i][k] == INF || G[k][j] == INF) continue; chmin(G[i][j], G[i][k] + G[k][j]); } } } int res = INF; for (int i = 1; i < N - 1; i++) { for (int j = 1; j < N - 1; j++) { if (i == j) continue; if (G[0][i] == INF || G[i][j] == INF || G[j][N - 1] == INF) continue; res = min(res, G[0][i] + G[i][j] + G[j][N - 1] + S[i] + S[j]); } } cout << res << '\n'; return 0; }