結果

問題 No.2477 Drifting
ユーザー 👑 tute7627tute7627
提出日時 2023-09-08 02:06:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 222,268 KB
実行使用メモリ 25,296 KB
最終ジャッジ日時 2023-09-08 20:18:28
合計ジャッジ時間 8,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 341 ms
25,292 KB
testcase_01 AC 232 ms
17,720 KB
testcase_02 AC 369 ms
25,296 KB
testcase_03 AC 214 ms
6,584 KB
testcase_04 AC 99 ms
5,372 KB
testcase_05 AC 177 ms
5,208 KB
testcase_06 AC 403 ms
20,904 KB
testcase_07 AC 403 ms
20,992 KB
testcase_08 AC 326 ms
18,632 KB
testcase_09 AC 220 ms
20,756 KB
testcase_10 AC 232 ms
22,536 KB
testcase_11 AC 221 ms
18,392 KB
testcase_12 AC 255 ms
16,664 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 218 ms
17,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  }
}
0