結果

問題 No.2477 Drifting
ユーザー 👑 tute7627tute7627
提出日時 2023-09-08 02:13:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 223,280 KB
実行使用メモリ 25,344 KB
最終ジャッジ日時 2023-09-08 20:17:55
合計ジャッジ時間 6,224 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
25,344 KB
testcase_01 AC 110 ms
17,768 KB
testcase_02 AC 166 ms
25,336 KB
testcase_03 AC 101 ms
6,588 KB
testcase_04 AC 54 ms
5,448 KB
testcase_05 AC 94 ms
5,320 KB
testcase_06 AC 194 ms
20,904 KB
testcase_07 AC 192 ms
20,816 KB
testcase_08 AC 160 ms
18,764 KB
testcase_09 AC 103 ms
20,600 KB
testcase_10 AC 108 ms
22,824 KB
testcase_11 AC 105 ms
18,500 KB
testcase_12 AC 107 ms
17,044 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 99 ms
17,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  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