結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 22:15:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 339 ms / 2,000 ms |
| コード長 | 1,088 bytes |
| コンパイル時間 | 1,756 ms |
| コンパイル使用メモリ | 202,096 KB |
| 実行使用メモリ | 23,872 KB |
| 最終ジャッジ日時 | 2025-04-09 15:39:47 |
| 合計ジャッジ時間 | 8,301 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll const inf = (ll)1e18;
using P = pair<ll, int>;
int main () {
int N, M, L; ll S, E;
cin >> N >> M >> L >> S >> E;
std::vector<P> gr[200020];
while (M--) {
int a, b; ll c;
cin >> a >> b >> c;
gr[--a].emplace_back(c, --b);
gr[b].emplace_back(c, a);
}
vector<ll> D1(N, inf), D2(N, inf);
D1[0] = D2[N - 1] = 0;
priority_queue<P, vector<P>, greater<P>> pque;
pque.emplace(0, 0);
while (!pque.empty()) {
auto [l, u] = pque.top();
pque.pop();
if (l != D1[u]) continue;
for (auto [c, v] : gr[u]) {
if (D1[v] > l + c) {
D1[v] = l + c;
pque.emplace(l + c, v);
}
}
}
pque.emplace(0, N - 1);
while (!pque.empty()) {
auto [l, u] = pque.top();
pque.pop();
if (l != D2[u]) continue;
for (auto [c, v] : gr[u]) {
if (D2[v] > l + c) {
D2[v] = l + c;
pque.emplace(l + c, v);
}
}
}
ll ans = inf * 3;
while (L--) {
int t;
cin >> t;
t --;
if (D1[t] < S + E) {
ans = min(ans, max(D1[t], S) + 1 + D2[t]);
}
}
cout << (ans >= inf ? -1ll : ans) << endl;
}