結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2014-11-11 00:47:36 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 36,964 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 01:17:15 |
合計ジャッジ時間 | 999 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf( "%d", &N ); | ~~~~~^~~~~~~~~~~~ main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf( "%d", S+i ); | ~~~~~^~~~~~~~~~~~~ main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf( "%d", &M ); | ~~~~~^~~~~~~~~~~~ main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf( "%d%d%d", &A, &B, &C ); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>#include<algorithm>#include<limits>#define repi(i,a,b) for(int i=(a);i<(b);++i)#define rep(i,a) repi(i,0,a)const int MAX_N = 50, INF = std::numeric_limits<int>::max()>>2;int N, M;int S[MAX_N], d[MAX_N][MAX_N];int main(){scanf( "%d", &N );rep( i, N )scanf( "%d", S+i );rep( i, N ) rep( j, N )d[i][j] = i==j?0:INF;scanf( "%d", &M );rep( i, M ){int A, B, C;scanf( "%d%d%d", &A, &B, &C );d[A][B] = d[B][A] = C;}rep( k, N ) rep( i, N ) rep( j, N )d[i][j] = std::min( d[i][j], d[i][k]+d[k][j] );int ans = INF;repi( i, 1, N-1 ) repi( j, 1, N-1 ) if( i != j )ans = std::min( ans, d[0][i]+S[i]+d[i][j]+S[j]+d[j][N-1] );printf( "%d\n", ans );return 0;}