結果
問題 |
No.2805 Go to School
|
ユーザー |
![]() |
提出日時 | 2024-07-15 15:08:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 1,451 bytes |
コンパイル時間 | 774 ms |
コンパイル使用メモリ | 64,544 KB |
実行使用メモリ | 23,772 KB |
最終ジャッジ日時 | 2025-04-09 15:42:15 |
合計ジャッジ時間 | 5,102 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:60:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 60 | scanf("%d%d%d%d%d", &n, &m, &l, &s, &e); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:64:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 64 | scanf("%d%d%d", &u, &v, &t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:70:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 70 | for (int i = 0; i < l; i++) scanf("%d", ts + i), ts[i]--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2805.cc: No.2805 Go to School - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 200000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using pii = pair<int,int>; using pli = pair<ll,int>; using vpii = vector<pii>; /* global variables */ vpii nbrs[MAX_N]; int ts[MAX_N]; ll ds0[MAX_N], ds1[MAX_N]; /* subroutines */ void dijkstra(int n, int st, ll ds[]) { fill(ds, ds + n, LINF); ds[st] = 0; priority_queue<pli> q; q.push({0, st}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; for (auto [v, t]: nbrs[u]) { ll vd = ud + t; if (ds[v] > vd) { ds[v] = vd; q.push({-vd, v}); } } } } /* main */ int main() { int n, m, l, s, e; scanf("%d%d%d%d%d", &n, &m, &l, &s, &e); for (int i = 0; i < m; i++) { int u, v, t; scanf("%d%d%d", &u, &v, &t); u--, v--; nbrs[u].push_back({v, t}); nbrs[v].push_back({u, t}); } for (int i = 0; i < l; i++) scanf("%d", ts + i), ts[i]--; dijkstra(n, 0, ds0); dijkstra(n, n - 1, ds1); ll mind = LINF; for (int i = 0; i < l; i++) if (ds0[ts[i]] < s + e) { ll d = max(ds0[ts[i]] , (ll)s) + 1 + ds1[ts[i]]; mind = min(mind, d); } printf("%lld\n", (mind < LINF) ? mind : -1LL); return 0; }