結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2015-05-18 19:25:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 892 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 35,676 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 05:28:54 |
合計ジャッジ時間 | 1,213 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 WA * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:14:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | for (int i = 0; i < N; i++) scanf("%d", S + i); | ~~~~~^~~~~~~~~~~~~ main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d", &M); | ~~~~~^~~~~~~~~~ main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d%d%d", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> using namespace std; #define INF 1000000007 #define N_MAX 50 int N, M; int S[N_MAX]; int dist[N_MAX][N_MAX]; int main() { scanf("%d", &N); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dist[i][j] = INF; for (int i = 0; i < N; i++) scanf("%d", S + i); 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++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } int res = INF; for (int i = 1; i < N - 2; i++) { for (int j = i + 1; j < N - 1; j++) { int sum = S[i] + S[j]; sum += min(dist[0][i] + dist[i][j] + dist[j][N - 1], dist[0][j] + dist[j][i] + dist[i][N - 1]); res = min(res, sum); } } printf("%d\n", res); return 0; }