結果

問題 No.3712 Urban Train
コンテスト
ユーザー tnakao0123
提出日時 2026-09-13 16:07:43
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 100 ms / 2,000 ms
+ 749µs
コード長 1,380 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 372 ms
コンパイル使用メモリ 78,188 KB
実行使用メモリ 17,604 KB
最終ジャッジ日時 2026-09-13 16:07:47
合計ジャッジ時間 4,266 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3712.cc:  No.3712 Urban Train - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 200000;
const long long LINF = 1LL << 62;

/* typedef */

using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using vpii = vector<pii>;

/* global variables */

vpii nbrs[MAX_N];
int as[MAX_N], bs[MAX_N], cs[MAX_N];
ll ds[MAX_N];

/* 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--;
    nbrs[u].push_back({v, w});
    nbrs[v].push_back({u, w});
  }
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);
  for (int i = 0; i < n; i++) scanf("%d", cs + i);

  fill(ds, ds + n, LINF);
  ds[0] = 1;
  priority_queue<pli> q;
  q.push({-ds[0], 0});

  while (! q.empty()) {
    auto [ud, u] = q.top(); q.pop();
    ud = -ud;
    if (ds[u] != ud) continue;

    if (u == n - 1) break;

    ll k = (ud + as[u] - 1) / as[u];
    ll dt = k * as[u];
    
    for (auto [v, w]: nbrs[u]) {
      ll vd = dt + w;
      if (k % bs[u] == 0) vd += min(cs[u], as[u]);
      if (ds[v] > vd) ds[v] = vd, q.push({-vd, v});
    }
  }

  printf("%lld\n", ds[n - 1]);
  
  return 0;
}

0