結果
問題 | No.2805 Go to School |
ユーザー |
|
提出日時 | 2024-07-05 11:28:24 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,555 bytes |
コンパイル時間 | 2,537 ms |
コンパイル使用メモリ | 213,568 KB |
実行使用メモリ | 22,484 KB |
最終ジャッジ日時 | 2024-07-05 11:28:41 |
合計ジャッジ時間 | 12,473 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 14 RE * 20 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:24:33: warning: narrowing conversion of 'b' from 'long long int' to 'int' [-Wnarrowing] 24 | g[a].push_back({b, c}); | ^ main.cpp:25:33: warning: narrowing conversion of 'a' from 'long long int' to 'int' [-Wnarrowing] 25 | g[b].push_back({a, c}); | ^
ソースコード
#include<bits/stdc++.h> using namespace std; struct edge{ int to; long long cost; }; using graph = vector<vector<edge>>; int main(){ long long n, m, l, s, e; cin >> n >> m >> l >> s >> e; assert(2 <= n && n <= 200000); assert(1 <= m && m <= 200000); assert(1 <= l && l <= n); assert(1 <= s && s <= 1000000000); assert(1 <= e && e <= 1000000000); graph g(n); for(int i = 0; i < m; i++){ long long a, b, c; cin >> a >> b >> c; assert(1 <= a && a <= n); assert(1 <= b && b <= n); assert(1 <= c && c <= 1000000000); a--, b--; g[a].push_back({b, c}); g[b].push_back({a, c}); } vector<int> t(n); for(int i = 0; i < l; i++){ int x; cin >> x; assert(1 <= x && x <= n); x--; t[x] = 1; } vector<long long> d(2*n, 1e18); d[0] = 0; using p = pair<long long, int>; priority_queue<p, vector<p>, greater<p>> pq; pq.push({0, 0}); while(!pq.empty()){ p q = pq.top(); pq.pop(); if(d[q.second] != q.first) continue; if(q.second%2 == 0 && t[q.second/2] == 1){ if(s <= q.first && q.first <= s+e-1){ if(d[q.second+1] > q.first+1){ d[q.second+1] = q.first+1; pq.push({q.first+1, q.second+1}); } }else if(q.first < s){ if(d[q.second+1] > s+1){ d[q.second+1] = s+1; pq.push({q.first+1, s+1}); } } } for(auto eg:g[q.second/2]){ if(d[eg.to*2+q.second%2] > d[q.second] + eg.cost){ d[eg.to*2+q.second%2] = d[q.second] + eg.cost; pq.push({d[q.second] + eg.cost, eg.to*2+q.second%2}); } } } if(d[2*n-1] > 1e17) cout << -1 << '\n'; else cout << d[2*n-1] << '\n'; }