結果

問題 No.3712 Urban Train
コンテスト
ユーザー yaaya
提出日時 2026-09-11 22:53:37
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 102 ms / 2,000 ms
+ 330µs
コード長 2,306 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,273 ms
コンパイル使用メモリ 346,164 KB
実行使用メモリ 20,560 KB
最終ジャッジ日時 2026-09-11 22:53:46
合計ジャッジ時間 5,900 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define ll long long
#define ull unsigned ll
#define ld long double
#define bl __int128_t
#define fi first
#define se second
#define vel vector<ll>
#define vvel vector<vel>
#define pll pair<ll,ll>
#define vepll vector<pll>
#define vvepll vector<vepll>
#define ves vector<string>
#define vem vector<mint>
#define vvem vector<vem>
#define pmm pair<mint,mint>
#define cleout(i) cout<<fixed<<setprecision(i)
template<class T>using PQ=priority_queue<T,vector<T>,greater<T>>;
//               上  右 下 左
vector<int> di={-1, 0, 1, 0};
vector<int> dj={ 0, 1, 0,-1};

vector<int> dx={ 0, 1, 0,-1};
vector<int> dy={ 1, 0,-1, 0};


vector<int> ddx={ 1, 1, 1, 0, -1, -1, -1, 0 };
vector<int> ddy={ 1, 0, -1, -1, -1, 0, 1, 1 };

ll inf=1000000000000000000;//1e18
// LLONG_MAX

mt19937_64 rng((ull)chrono::steady_clock::now().time_since_epoch().count());

void _solve(){
    ll N,M;
    cin>>N>>M;
    vvepll G(N);
    rep(i,0,M){
        ll x,y,z;
        cin>>x>>y>>z;
        x--;
        y--;
        G[x].push_back({z,y});
        G[y].push_back({z,x});
    }
    vel a(N),b(N),c(N);
    rep(i,0,N)cin>>a[i];
    rep(i,0,N)cin>>b[i];
    rep(i,0,N)cin>>c[i];
    vel ans(N,inf);
    PQ<pll> pq;
    ans[0]=1;
    pq.push({1,0});
    while(pq.size()){
        ll now=pq.top().se;
        pq.pop();
        for(auto [C,y]:G[now]){
            auto find=[&](ll x,ll y){
                return (x+y-1)/y*y;
            };
            ll t=find(ans[now],a[now]);
            if(t/a[now]%b[now]==0){
                t+=c[now];
            }
            t+=C;
            if(ans[y]>t){
                ans[y]=t;
                pq.push({ans[y],y});
            }
            t=find(ans[now],a[now]);
            if(t/a[now]%b[now]==0){
                t+=a[now]+C;
            }else{
                t=find(t,a[now]*b[now])+c[now]+C;
            }
            if(ans[y]>t){
                ans[y]=t;
                pq.push({ans[y],y});
            }
        }
    }
    cout<<ans.back()<<"\n";
}


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

    
    ll _;
    bool multitest=0;
    if(multitest)cin>>_;
    else _=1;
    rep(__,0,_){
        _solve();
    }
}
0