結果
| 問題 | 
                            No.2477 Drifting
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2024-06-21 14:09:28 | 
| 言語 | C++17(gcc12)  (gcc 12.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,995 bytes | 
| コンパイル時間 | 4,259 ms | 
| コンパイル使用メモリ | 107,160 KB | 
| 最終ジャッジ日時 | 2025-02-21 23:40:12 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 3 | 
| other | AC * 6 TLE * 1 -- * 7 | 
ソースコード
/* -*- coding: utf-8 -*-
 *
 * 2477.cc:  No.2477 Drifting - yukicoder
 */
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_M = 200000;
const int MAX_GN = MAX_N + MAX_M;
const int MAX_K = 200000;
const long long LINF = 1LL << 62;
/* typedef */
using ll = long long;
using pii = pair<int,int>;
using vpii = vector<pii>;
using si = set<int>;
using mpii = map<pii,int>;
using pli = pair<ll,int>;
/* global variables */
vpii es[MAX_N], nbrs[MAX_GN];
int orgs[MAX_GN];
si exs[MAX_GN];
ll ds[MAX_GN];
/* subroutines */
/* main */
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    es[u].push_back({v, w});
  }
  for (int i = 0; i < n; i++) orgs[i] = i;
  
  int gn = n;
  mpii evs;
  int k;
  scanf("%d", &k);
  while (k--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--, c--;
    auto mit = evs.find({a, b});
    int u = -1;
    if (mit != evs.end()) u = mit->second;
    else {
      u = evs[{a, b}] = gn++;
      orgs[u] = b;
    }
    exs[u].insert(c);
  }
  //printf(" gn=%d\n", gn);
  for (int u = 0; u < gn; u++) {
    int ou = orgs[u];
    for (auto [v, w]: es[ou]) {
      if (! exs[u].empty() && exs[u].find(v) != exs[u].end())
	continue;
      auto mit = evs.find({ou, v});
      if (mit != evs.end()) v = mit->second;
      nbrs[u].push_back({v, w});
    }
  }
  fill(ds, ds + gn, LINF);
  ds[0] = 0;
  priority_queue<pli> q;
  q.push({0, 0});
  ll mind = LINF;
  while (! q.empty()) {
    auto [ud, u] = q.top(); q.pop();
    ud = -ud;
    if (ds[u] != ud) continue;
    if (u == n - 1) { mind = ud; break; }
    for (auto [v, w]: nbrs[u]) {
      ll vd = ud + w;
      if (ds[v] > vd) {
	ds[v] = vd;
	q.push({-vd, v});
      }
    }
  }
  printf("%lld\n", (mind < LINF) ? mind : -1LL);
  
  return 0;
}
            
            
            
        
            
tnakao0123