結果

問題 No.2805 Go to School
ユーザー rei
提出日時 2024-07-12 21:42:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 2,008 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 114,480 KB
最終ジャッジ日時 2025-02-22 03:43:25
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i8 = int8_t;
using i32 = int;
using i64 = long long;
// using i128 = __int128;
using u64 = unsigned long long;
using ll = long long;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
i64 pow(i64 j, i64 n) {
i64 res = 1;
while (n > 0) {
if (n & 1)
res *= j;
j *= j;
n >>= 1;
}
return res;
}
i64 n, m, l, s, e;
void _main() {
cin >> n >> m >> l >> s >> e;
vector<vector<pair<i64, i64>>> g(n);
vector<i64> toire(l);
for (i64 i = 0; i < m; i++) {
i64 a, b, t;
cin >> a >> b >> t;
a--, b--;
g[a].push_back({b, t});
g[b].push_back({a, t});
}
for (i64 i = 0; i < l; i++) {
cin >> toire[i];
toire[i]--;
}
vector<i64> f(n, 1ll << 60);
using el = pair<i64, i64>;
priority_queue<el, vector<el>, greater<el>> que1;
f[0] = 0;
que1.push({0, 0});
while (!que1.empty()) {
auto [d, i] = que1.top();
que1.pop();
if (f[i] < d) {
continue;
}
for (auto [ni, t] : g[i]) {
if (f[ni] > f[i] + t) {
f[ni] = f[i] + t;
que1.push({f[ni], ni});
}
}
}
priority_queue<el, vector<el>, greater<el>> que2;
vector<i64> b(n, 1ll << 60);
b[n - 1] = 0;
que2.push({0, n - 1});
while (!que2.empty()) {
auto [d, i] = que2.top();
que2.pop();
if (b[i] < d) {
continue;
}
for (auto [ni, t] : g[i]) {
if (b[ni] > b[i] + t) {
b[ni] = b[i] + t;
que2.push({b[ni], ni});
}
}
}
i64 ans = 1ll << 60;
for (auto i : toire) {
if (f[i] < s) {
ans = min(ans, s + 1 + b[i]);
} else if (f[i] < s + e) {
ans = min(ans, f[i] + 1 + b[i]);
}
}
if (ans == 1ll << 60) {
cout << "-1\n";
} else {
cout << ans << "\n";
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0