結果

問題 No.3111 Toll Optimization
ユーザー pia019
提出日時 2025-04-18 20:45:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 360 ms / 5,000 ms
コード長 1,696 bytes
コンパイル時間 7,175 ms
コンパイル使用メモリ 351,560 KB
実行使用メモリ 25,996 KB
最終ジャッジ日時 2025-04-18 20:45:23
合計ジャッジ時間 16,773 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const ll MOD = 1000000007;
const double INFD = 1.0E10;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
//const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using Pair = pair<ll, ll>;
using Graph = vector<vector<ll, ll> >;
using mint = atcoder::modint1000000007;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int n, m, k; cin >> n >> m >> k;
    vector<ll> C(m);
    for (int i = 0; i < m; i++) cin >> C[i];
    vector<vector<pair<ll, ll>>> G(n);
    for (int i = 0; i < m; i++){
        int u, v; cin >> u >> v; u--; v--;
        G[u].push_back({v, C[i]});
        G[v].push_back({u, C[i]});
    }
    
    
    vector<vector<ll>> dp(n, vector<ll>(k + 1, INFLL));
    using Pair = tuple<ll, ll, ll>;
    priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
    pq.push({0, 0, 0});
    while (!pq.empty()){
        auto [d, v, cnt] = pq.top(); pq.pop();
        //cerr << d << ' ' << v << ' ' << cnt << endl;
        if (dp[v][cnt] < INFLL) continue;
        dp[v][cnt] = d;
        for (auto [nv, w] : G[v]){
            for (int i = 0; i < 2; i++){
                if (cnt + i > k) continue;
                if (dp[nv][cnt + i] < INFLL) continue;
                pq.push({d + (i == 0 ? w : 0), nv, cnt + i});
            }
        }
    }
    
    ll ans = INFLL;
    for (int i = 0; i <= k; i++) ans = min(ans, dp[n - 1][i]);
    
    cout << (ans < INFLL ? ans : -1) << endl;
    
    return 0;
}
0