結果
問題 | No.2805 Go to School |
ユーザー |
|
提出日時 | 2024-06-18 19:35:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,231 bytes |
コンパイル時間 | 1,799 ms |
コンパイル使用メモリ | 179,152 KB |
実行使用メモリ | 23,360 KB |
最終ジャッジ日時 | 2024-07-04 21:13:23 |
合計ジャッジ時間 | 8,040 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 22 WA * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; struct Edge { long long to; long long cost; }; vector<long long> dijkstra(const vector<vector<Edge>> &G, int s) { int N = G.size(); vector<long long> dis(N, LLONG_MAX/16); priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq; dis[s] = 0; pq.emplace(dis[s], s); while (!pq.empty()) { pair<long long, int> p = pq.top(); pq.pop(); int v = p.second; if (dis[v] < p.first) { continue; } for (auto &e : G[v]) { if (dis[e.to] > dis[v] + e.cost) { dis[e.to] = dis[v] + e.cost; pq.emplace(dis[e.to], e.to); } } } return dis; } int main() { ll N,M,L,S,E; cin >> N >> M >> L >> S >> E; vector<vector<Edge>> G(N); for (int i = 0; i < M; i++) { ll a,b,c; cin >> a >> b >> c; a--;b--; G[a].push_back({b,c}); G[b].push_back({a,c}); } vector<ll> T(L); for (int i = 0; i < L; i++) { cin >> T[i]; T[i]--; } //家からダイクストラ vector<ll> dis1 = dijkstra(G, 0); //そもそもお腹が痛くなる前に学校につけるかどうか if (dis1[N-1] < S) { cout << dis1[N-1]<< endl; return 0; } //学校からダイクストラ vector<ll> dis2 = dijkstra(G, N-1); //それぞれのトイレについて間に合うかどうかを調べる ll ans = LLONG_MAX; for (int i = 0; i < L; i++) { ll t = T[i]; ll time = dis1[t]; //そもそもトイレの時間に間に合うかどうか if (time < S) { //トイレまで待つ+滞在期間 time = S+1; }else if(S<=time and time < S+E) { //ちょうどお腹が痛いから滞在する time += 1; }else { //間に合わない... continue; } //トイレto学校 time += dis2[t]; ans = min(ans, time); } //answer if (ans == LLONG_MAX) { cout << -1 << endl; }else { cout << ans << endl; } }