結果

問題 No.3712 Urban Train
コンテスト
ユーザー GOTKAKO
提出日時 2026-09-11 21:42:42
言語 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  
実行時間 112 ms / 2,000 ms
+ 249µs
コード長 1,016 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,265 ms
コンパイル使用メモリ 224,012 KB
実行使用メモリ 20,432 KB
最終ジャッジ日時 2026-09-11 21:42:50
合計ジャッジ時間 4,142 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<vector<pair<int,long long>>> Graph(N);
    for(int i=0; i<M; i++){
        int u,v; cin >> u >> v;
        u--; v--;
        int w; cin >> w;
        Graph.at(u).push_back({v,w});
        Graph.at(v).push_back({u,w});
    }
    vector<long long> dist(N,1e18),A(N),B(N),C(N);
    for(auto &a : A) cin >> a;
    for(auto &a : B) cin >> a;
    for(auto &a : C) cin >> a;
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<>> Q;
    dist.at(0) = 0,Q.push({0,0});
    while(Q.size()){
        auto [d,pos] = Q.top(); Q.pop();
        if(dist.at(pos) != d) continue;
        if(d == 0 || d%A.at(pos)) d += A.at(pos)-d%A.at(pos);
        if(d/A.at(pos)%B.at(pos) == 0) d += min(A.at(pos),C.at(pos));
        for(auto [to,w] : Graph.at(pos)) if(dist.at(to) > d+w) dist.at(to) = d+w,Q.push({d+w,to});
    }
    cout << dist.at(N-1) << endl;
}
0