結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
opqopq_
|
| 提出日時 | 2015-08-28 17:23:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,040 bytes |
| コンパイル時間 | 266 ms |
| コンパイル使用メモリ | 35,680 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 01:26:13 |
| 合計ジャッジ時間 | 1,099 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:14:38: 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:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &M);
| ~~~~~^~~~~~~~~~
main.cpp:18:14: 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 100000007
#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;
}
opqopq_