結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2015-04-29 19:50:18 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,360 bytes |
コンパイル時間 | 439 ms |
コンパイル使用メモリ | 48,404 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:13:01 |
合計ジャッジ時間 | 1,408 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d%d%d", &N, &C, &V); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:27:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d", &data[j][i]); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> #include <queue> using namespace std; #define MAX_N 50 #define MAX_V 1500 #define INF 1000000007 struct State { int n, c, t; bool operator < (const State& r) const { return t > r.t; } State(int x, int y, int z) : n(x), c(y), t(z) {} }; int N, C, V; int data[MAX_V][4]; vector<State> edge[MAX_N]; int maxm[MAX_N][2]; int main() { scanf("%d%d%d", &N, &C, &V); for (int i = 0; i < 4; i++) { for (int j = 0; j < V; j++) { scanf("%d", &data[j][i]); if (i < 2) data[j][i]--; } } for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { maxm[i][j] = INF; } } for (int i = 0; i < V; i++) { edge[data[i][0]].emplace_back(data[i][1], data[i][2], data[i][3]); } priority_queue<State> pq; maxm[0][0] = maxm[0][1] = 0; pq.emplace(0, 0, 0); int res = 0; while (!pq.empty()) { State s = pq.top(); pq.pop(); if (s.n == N - 1) { res = s.t; break; } if (maxm[s.n][0] < s.c && maxm[s.n][1] < s.t) continue; for (State n : edge[s.n]) { n.c += s.c, n.t += s.t; if (C < n.c) continue; if (maxm[n.n][0] < n.c && maxm[n.n][1] < n.t) continue; if (maxm[n.n][0] == INF) maxm[n.n][0] = n.c, maxm[n.n][1] = n.t; maxm[n.n][0] = max(maxm[n.n][0], n.c); maxm[n.n][1] = max(maxm[n.n][1], n.t); pq.push(n); } } printf("%d\n", res ? res : -1); return 0; }