結果

問題 No.2477 Drifting
ユーザー igeee
提出日時 2023-09-18 09:28:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 1,912 bytes
コンパイル時間 3,794 ms
コンパイル使用メモリ 267,296 KB
最終ジャッジ日時 2025-02-16 23:21:32
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repn(i,end) for(long long i = 0; i <= (long long)(end); i++)
#define reps(i,start,end) for(long long i = start; i < (long long)(end); i++)
#define repsn(i,start,end) for(long long i = start; i <= (long long)(end); i++)
#define ll long long
#define ld long double
#define all(a)  (a).begin(),(a).end()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
 
template<class T> bool chmin(T& a, T b){
 if(a > b){
  a = b;
  return true;
 }
  return false;
}
 
template<class T> bool chmax(T& a, T b){
 if(a < b){
  a = b;
  return true;
 }
  return false;
}
//grid探索用
vector<ll> _tate = {0,-1,0,1,1,-1,-1,1};
vector<ll> _yoko = {1,0,-1,0,1,1,-1,-1};
  
ll lpow(ll x,ll n){
  ll ans = 1;
  while(n >0){
    if(n & 1)ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
 
int main(){
  ll n,m;cin >> n >> m;
  vector<set<pair<ll,ll>>> g(n);//頂点,距離
  rep(i,m){
    ll u,v,w;cin >> u >> v >> w;
    u--;v--;
    g[u].insert({v,w});
  }
  ll K;cin >> K;
  set<tuple<ll,ll,ll>> abc;
  rep(z,K){
    ll a,b,c;cin >> a >> b >> c;
    a--;b--;c--;
    abc.insert({a,b,c});
  }
  vector<set<pair<ll,ll>>> in(n);//距離,頂点(from)
  vector<ll> dis(n,INF);
  dis[0] = 0;
  for(auto &p:g[0]){
    in[p.first].insert({dis[0] + p.second,0});
    
  }
  //0は別でやる

  reps(i,1,n){
    for(auto &p:in[i]){
      vector<pair<ll,ll>> used;
      auto [cost,from] = p;
      chmin(dis[i],cost);
      for(auto &q: g[i]){
        auto [to,w] = q;
        if(abc.count({from,i,to}))continue;
        in[to].insert({cost + w,i});
        used.push_back({to,w});
      }
      for(auto &pr:used){
        g[i].erase(pr);
      }
    }
  }
  if(dis[n-1] == INF){
    cout << -1 << endl;
  }else{
    cout << dis[n-1] << endl;
  }

}
0