結果
問題 | No.2477 Drifting |
ユーザー |
![]() |
提出日時 | 2023-09-08 02:06:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 487 ms / 2,000 ms |
コード長 | 1,306 bytes |
コンパイル時間 | 2,691 ms |
コンパイル使用メモリ | 215,836 KB |
最終ジャッジ日時 | 2025-02-16 19:17:44 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int N, M; cin >> N >> M; assert(3 <= N && N <= 2e5); assert(0 <= M && M <= 2e5); vector<vector<pair<int, int>>>g(N); for(int i = 0; i < M; i++){ int u, v, w; cin >> u >> v >> w; assert(1 <= u && u < v && v <= N); assert(1 <= w && w <= 1e9); u--; v--; g[u].emplace_back(v, w); } vector<vector<pair<int, int>>>ng(N); int K; cin >> K; for(int i = 0; i < K; i++){ int a, b, c; cin >> a >> b >> c; assert(1 <= a && a < b && b < c && c <= N); a--; b--; c--; ng[b].emplace_back(a, c); } vector<vector<pair<long long, int>>>dp(N); dp[0].emplace_back(0, -1); for(int i = 0; i < N; i++){ sort(dp[i].begin(), dp[i].end()); sort(ng[i].begin(), ng[i].end()); set<int>st; for(int j = 0; j < g[i].size(); j++)st.insert(j); for(auto [dist, from]: dp[i]){ for(auto it = st.begin(); it != st.end();){ auto [to, cost] = g[i][*it]; if(binary_search(ng[i].begin(), ng[i].end(), make_pair(from, to))){ it++; } else{ dp[to].emplace_back(dist + cost, i); it = st.erase(it); } } } } if(dp[N - 1].empty()){ cout << -1 << endl; } else{ cout << dp[N - 1][0].first << endl; } }