結果
問題 | No.2805 Go to School |
ユーザー | Akshaj Padmakar |
提出日時 | 2024-07-12 22:51:37 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 220 ms / 2,000 ms |
コード長 | 1,726 bytes |
コンパイル時間 | 1,731 ms |
コンパイル使用メモリ | 179,284 KB |
実行使用メモリ | 22,552 KB |
最終ジャッジ日時 | 2024-07-16 01:41:08 |
合計ジャッジ時間 | 5,861 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 74 ms
17,536 KB |
testcase_05 | AC | 94 ms
14,124 KB |
testcase_06 | AC | 52 ms
9,292 KB |
testcase_07 | AC | 44 ms
9,088 KB |
testcase_08 | AC | 76 ms
14,284 KB |
testcase_09 | AC | 53 ms
9,324 KB |
testcase_10 | AC | 46 ms
9,252 KB |
testcase_11 | AC | 220 ms
21,264 KB |
testcase_12 | AC | 117 ms
14,572 KB |
testcase_13 | AC | 171 ms
18,556 KB |
testcase_14 | AC | 24 ms
6,400 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 78 ms
11,440 KB |
testcase_19 | AC | 52 ms
8,948 KB |
testcase_20 | AC | 120 ms
15,832 KB |
testcase_21 | AC | 183 ms
20,740 KB |
testcase_22 | AC | 70 ms
11,008 KB |
testcase_23 | AC | 113 ms
14,484 KB |
testcase_24 | AC | 114 ms
14,368 KB |
testcase_25 | AC | 32 ms
8,868 KB |
testcase_26 | AC | 137 ms
22,552 KB |
testcase_27 | AC | 75 ms
18,008 KB |
testcase_28 | AC | 7 ms
7,680 KB |
testcase_29 | AC | 12 ms
8,448 KB |
testcase_30 | AC | 36 ms
13,440 KB |
testcase_31 | AC | 55 ms
10,752 KB |
testcase_32 | AC | 106 ms
19,288 KB |
testcase_33 | AC | 164 ms
19,800 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 54 ms
9,192 KB |
testcase_37 | AC | 60 ms
10,752 KB |
testcase_38 | AC | 119 ms
16,512 KB |
コンパイルメッセージ
main.cpp: In lambda function: main.cpp:38:30: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 38 | auto [d, u] = pq.top(); | ^ main.cpp:43:35: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 43 | for (auto [v, weight] : g[u]) { | ^
ソースコード
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #include "algo/debug.h" #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long const int INF = 1e15; void solve() { int n, m, l, s, e; cin >> n >> m >> l >> s >> e; vector<vector<pair<int, int>>> g(n); for (int i = 0, a, b, w; i < m; i++) { cin >> a >> b >> w; a--, b--; g[a].push_back({b, w}); g[b].push_back({a, w}); } vector<int> spec(l); for (auto &x : spec) { cin >> x; x--; } e = s + e; vector<vector<int>> min_dist(2, vector<int>(n, INF)); // Lambda function for Dijkstra's algorithm auto dijkstra = [&](int start, int id) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; min_dist[id][start] = 0; pq.push({0, start}); // {distance, node} while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (d > min_dist[id][u]) continue; // Skip if we have already found a better path for (auto [v, weight] : g[u]) { if (min_dist[id][u] + weight < min_dist[id][v]) { min_dist[id][v] = min_dist[id][u] + weight; pq.push({min_dist[id][v], v}); } } } }; dijkstra(0, 0); dijkstra(n - 1, 1); int ans = INF; for (auto &x : spec) { if (min_dist[0][x] < e) { ans = min(ans, max(s, min_dist[0][x]) + 1 + min_dist[1][x]); } } cout << (ans == INF ? -1 : ans) << '\n'; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } // cerr << "Time elapsed: " << ((long double)clock() / CLOCKS_PER_SEC) << " s.\n"; }