結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 08:36:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,518 bytes |
| コンパイル時間 | 419 ms |
| コンパイル使用メモリ | 52,068 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 01:17:16 |
| 合計ジャッジ時間 | 1,198 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:15:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(int i=0;i<N;i++){scanf("%d", S+i);}
| ~~~~~^~~~~~~~~~~
main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | scanf("%d", &M);
| ~~~~~^~~~~~~~~~
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
#include <queue>
#define mp std::make_pair
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;
int N, M, S[50];
std::vector<P> G[50];
int main(){
scanf("%d", &N);
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);
G[a].push_back(mp(b, c));
G[b].push_back(mp(a, c));
}
int d[50][52];
std::fill(&d[0][0], &d[0][0]+50*52, 1001001001);
d[0][50] = 0;
std::priority_queue<State, std::vector<State>, std::greater<State> > q;
q.push(mp(0, mp(0, 50)));
while(!q.empty()){
State s = q.top(); q.pop();
int cost = s.first, from = s.second.first, state = s.second.second;
if(state == 50 && from != 0 && from != N-1 && d[from][from] > cost + S[from]){
d[from][from] = cost + S[from];
q.push(mp(d[from][from], mp(from, from)));
}
if(0 <= state && state < N && from != 0 && from != N-1 && from != state && d[from][51] > cost + S[from]){
d[from][51] = cost + S[from];
q.push(mp(d[from][51], mp(from, 51)));
}
for(auto e : G[from]){
if(d[e.first][state] > cost + e.second){
d[e.first][state] = cost + e.second;
q.push(mp(d[e.first][state], mp(e.first, state)));
}
}
}
printf("%d\n", d[N-1][51]);
}
tottoripaper