結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2025-06-01 19:45:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,065 bytes |
コンパイル時間 | 3,462 ms |
コンパイル使用メモリ | 286,140 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-01 19:45:16 |
合計ジャッジ時間 | 7,463 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 4 |
other | WA * 20 RE * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct Edge { int to, cost, time; }; int main() { int N, C, V; cin >> N >> C >> V; vector<vector<Edge>> graph(N); for (int i = 0; i < V; i++) { int s, t, y, m; cin >> s >> t >> y >> m; s--, t--; graph[s].push_back({t, y, m}); } vector<int> dp(C+1, INT_MAX); dp[0] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; pq.push({0, 0}); while (!pq.empty()) { auto [curr_time, curr_cost] = pq.top(); pq.pop(); if (curr_time > dp[curr_cost]) continue; for (const auto& [to, cost, time] : graph[0]) { int new_cost = curr_cost + cost; int new_time = curr_time + time; if (new_cost <= C && new_time < dp[new_cost]) { dp[new_cost] = new_time; pq.push({new_time, new_cost}); } } } int ans = *min_element(dp.begin(), dp.end()); cout << (ans == INT_MAX ? -1 : ans) << endl; return 0; }