結果

問題 No.2477 Drifting
ユーザー Nzt3Nzt3
提出日時 2023-09-21 15:26:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 222,468 KB
実行使用メモリ 36,388 KB
最終ジャッジ日時 2023-09-21 15:26:19
合計ジャッジ時間 7,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
36,244 KB
testcase_01 AC 137 ms
25,072 KB
testcase_02 AC 213 ms
36,388 KB
testcase_03 AC 313 ms
14,804 KB
testcase_04 AC 120 ms
9,308 KB
testcase_05 AC 332 ms
13,136 KB
testcase_06 AC 324 ms
32,844 KB
testcase_07 AC 320 ms
32,960 KB
testcase_08 AC 220 ms
28,116 KB
testcase_09 AC 99 ms
29,916 KB
testcase_10 AC 111 ms
34,260 KB
testcase_11 AC 97 ms
25,192 KB
testcase_12 AC 122 ms
26,864 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 94 ms
24,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<vector<array<int,2>>>G(N);
  for(int i=0;i<M;i++){
    int u,v,w;
    cin>>u>>v>>w;
    --u,--v;
    G[u].push_back({v,w});
  }
  int K;
  cin>>K;
  vector<set<array<int,2>>>ng(N);
  for(int i=0;i<K;i++){
    int a,b,c;
    cin>>a>>b>>c;
    --a,--b,--c;
    ng[b].insert({a,c});
  }
  vector<ll>dist(N,1e18);
  vector<vector<pair<ll,int>>>dists(N,vector<pair<ll,int>>(1,{(ll)1e18,-1}));
  dists[0].push_back({0,0});
  for(int i=0;i<N;i++){
    sort(dists[i].begin(),dists[i].end());
    dist[i]=dists[i][0].first;
    for(auto [j,w]:G[i]){
      for(auto [d,k]:dists[i]){
        if(k==-1)break;
        if(ng[i].find({k,j})==ng[i].end()){
          dists[j].push_back({d+w,i});
          break;
        }
      }
    }
  }
  ll ans=dist[N-1];
  cout<<(ans==1e18?-1ll:ans)<<'\n';
}
0