結果

問題 No.2477 Drifting
ユーザー 👑 tute7627tute7627
提出日時 2023-09-08 19:07:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,416 bytes
コンパイル時間 2,370 ms
コンパイル使用メモリ 219,028 KB
実行使用メモリ 25,576 KB
最終ジャッジ日時 2023-09-08 20:18:34
合計ジャッジ時間 12,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
25,288 KB
testcase_01 AC 100 ms
17,840 KB
testcase_02 AC 164 ms
25,576 KB
testcase_03 WA -
testcase_04 AC 50 ms
4,896 KB
testcase_05 AC 108 ms
5,300 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 1,870 ms
18,636 KB
testcase_09 AC 222 ms
20,928 KB
testcase_10 AC 276 ms
22,876 KB
testcase_11 AC 211 ms
18,452 KB
testcase_12 AC 119 ms
17,008 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 149 ms
17,916 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());
    vector<long long>mi(g[i].size(), 1e18);
    int lim = 1000;
    for(auto [dist, from]: dp[i]){
      lim--;
      if(lim < 0)break;
      for(int j = 0; j < g[i].size(); j++){
        auto [to, cost] = g[i][j];
        if(binary_search(ng[i].begin(), ng[i].end(), make_pair(from, to)))continue;
        mi[j] = min(mi[j], dist + cost);
      }
    }
    for(int j = 0; j < g[i].size(); j++){
      if(mi[j] != 1e18)dp[g[i][j].first].emplace_back(mi[j], i);
    }
  }
  if(dp[N - 1].empty()){
    cout << -1 << endl;
  }
  else{
    cout << dp[N - 1][0].first << endl;
  }
}
0