結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-19 16:51:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 198 ms / 2,000 ms |
| コード長 | 2,040 bytes |
| コンパイル時間 | 1,056 ms |
| コンパイル使用メモリ | 105,648 KB |
| 実行使用メモリ | 19,448 KB |
| 最終ジャッジ日時 | 2025-04-09 15:42:33 |
| 合計ジャッジ時間 | 5,212 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
#include <functional>
using namespace std;
int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M, L, S, E, i, a, b, t;
long long ans = LONG_LONG_MAX;
cin >> N >> M >> L >> S >> E;
vector<vector<pair<int, int>>> edges(N, vector<pair<int, int>>());
vector<int> T(L);
vector<long long> dist_from_start(N, LONG_LONG_MAX), dist_from_goal(N, LONG_LONG_MAX);
for (i = 0; i != M; ++i)
{
cin >> a >> b >> t, --a, --b;
edges[a].emplace_back(t, b);
edges[b].emplace_back(t, a);
}
for (i = 0; i != L; ++i)
cin >> T[i], --T[i];
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
pq.emplace(dist_from_start[0] = 0, 0);
while (!pq.empty())
{
if (pq.top().first == dist_from_start[pq.top().second])
{
for (i = 0; i != edges[pq.top().second].size(); ++i)
if (dist_from_start[edges[pq.top().second][i].second] > pq.top().first + edges[pq.top().second][i].first)
pq.emplace(dist_from_start[edges[pq.top().second][i].second] = pq.top().first + edges[pq.top().second][i].first, edges[pq.top().second][i].second);
}
pq.pop();
}
pq.emplace(dist_from_goal[N - 1] = 0, N - 1);
while (!pq.empty())
{
if (pq.top().first == dist_from_goal[pq.top().second])
{
for (i = 0; i != edges[pq.top().second].size(); ++i)
if (dist_from_goal[edges[pq.top().second][i].second] > pq.top().first + edges[pq.top().second][i].first)
pq.emplace(dist_from_goal[edges[pq.top().second][i].second] = pq.top().first + edges[pq.top().second][i].first, edges[pq.top().second][i].second);
}
pq.pop();
}
for (i = 0; i != L; ++i)
if (dist_from_start[T[i]] < S + E && dist_from_goal[T[i]] != LONG_LONG_MAX && max(static_cast<long long>(S), dist_from_start[T[i]]) + 1 + dist_from_goal[T[i]] < ans)
ans = max(static_cast<long long>(S), dist_from_start[T[i]]) + 1 + dist_from_goal[T[i]];
if (ans == LONG_LONG_MAX)
cout << "-1\n";
else
cout << ans << '\n';
return 0;
}