結果

問題 No.3111 Toll Optimization
コンテスト
ユーザー たけ
提出日時 2026-03-08 16:47:44
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3,075 ms / 5,000 ms
コード長 1,500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,727 ms
コンパイル使用メモリ 354,824 KB
実行使用メモリ 20,320 KB
最終ジャッジ日時 2026-03-08 16:56:22
合計ジャッジ時間 22,674 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
#define print(a) cout<<a<<'\n'
#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define drep(i,a,b) for(ll i=(a);i>(b);i--)
#define all(v) v.begin(),v.end()
#define dall(v) v.rbegin(),v.rend()
#define pqmaxl priority_queue<ll>
#define pqminl priority_queue<ll,vector<ll>,greater<ll>>
//ほんへ
int main(){
    //呪い
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //やれ
    ll n,m,k,u,v;
    cin>>n>>m>>k;
    vl c(m);
    rep(i,0,m)cin>>c[i];
    vector<vector<pair<ll,ll>>>edge(n);
    rep(i,0,m){
        cin>>u>>v;
        edge[u-1].push_back({v-1,c[i]});
        edge[v-1].push_back({u-1,c[i]});
    }
    priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>>st;
    vector<vl>now(n,vl(k+1,1e18));
    st.push({0,0,0});
    now[0]=vl(k+1,0);
    while(!st.empty()){
        auto it=st.top();
        st.pop();
        ll cos=get<0>(it),pot=get<1>(it),used=get<2>(it);
        for(auto p:edge[pot]){
            if(cos>now[pot][used])continue;
            if(cos+p.second<now[p.first][used]){
                now[p.first][used]=cos+p.second;
                st.push({cos+p.second,p.first,used});
            }
            if(used<k&&cos<now[p.first][used+1]){
                now[p.first][used+1]=cos;
                st.push({cos,p.first,used+1});
            }
        }
    }
    ll res=*min_element(all(now[n-1]));
    if(res==1e18)print(-1);
    else print(res);
}
0