結果

問題 No.2805 Go to School
ユーザー Akshaj Padmakar
提出日時 2024-07-12 22:51:37
言語 C++14
(gcc 13.3.0 + boost 1.87.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
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]) {
      |                                   ^

ソースコード

diff #
プレゼンテーションモードにする

#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";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0