結果
| 問題 | 
                            No.3111 Toll Optimization
                             | 
                    
| コンテスト | |
| ユーザー | 
                             mencotton
                         | 
                    
| 提出日時 | 2025-04-19 01:05:13 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 400 ms / 5,000 ms | 
| コード長 | 2,137 bytes | 
| コンパイル時間 | 908 ms | 
| コンパイル使用メモリ | 83,608 KB | 
| 実行使用メモリ | 49,992 KB | 
| 最終ジャッジ日時 | 2025-04-19 01:05:35 | 
| 合計ジャッジ時間 | 12,786 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 70 | 
ソースコード
#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1 << 30) - 10;
const ll LINF = 1LL << 60;
inline void output_YesNo(bool x) { cout << (x ? "Yes" : "No") << endl; }
template<typename T>
inline void chmax(T &lhs, const T &rhs) { lhs = max(lhs, rhs); }
template<typename T>
inline void chmin(T &lhs, const T &rhs) { lhs = min(lhs, rhs); }
// #include <iomanip>
//
// void init_output() { cout << fixed << setprecision(15); }
struct edge {
    int to;
    ll cost;
};
struct status {
    ll cost;
    int v;
    bool operator<(const status &rhs) const { return cost < rhs.cost; };
    bool operator>(const status &rhs) const { return cost > rhs.cost; };
};
vector<ll> dijkstra(int s, vector<vector<edge>> &graph) {
    priority_queue<status, vector<status>, greater<>> que;
    vector<ll> dis(graph.size(), LINF);
    dis[s] = 0;
    que.push({0, s});
    while (!que.empty()) {
        status now = que.top();
        que.pop();
        if (dis[now.v] < now.cost)continue;
        for (auto next: graph[now.v]) {
            if (dis[next.to] > now.cost + next.cost) {
                dis[next.to] = now.cost + next.cost;
                que.push({dis[next.to], next.to});
            }
        }
    }
    return dis;
}
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> cost(m);
    for (auto &x: cost)cin >> x;
    vector<vector<edge>> graph(n * (k + 1));
    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to, from--, to--;
        for (int j = 0; j <= k; j++) {
            int u = from + n * j;
            int v = to + n * j;
            graph[u].push_back({v, cost[i]});
            graph[v].push_back({u, cost[i]});
            if (j >= 1) {
                graph[u].push_back({v - n, 0});
                graph[v].push_back({u - n, 0});
            }
        }
    }
    vector<ll> dis = dijkstra(n * k, graph);
    ll ret = LINF;
    for (int j = 0; j <= k; j++) chmin(ret, dis[n - 1 + n * j]);
    cout << (ret == LINF ? -1 : ret) << endl;
    return 0;
}
            
            
            
        
            
mencotton