結果
| 問題 | No.3111 Toll Optimization | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-06-30 21:17:01 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,029 bytes | 
| コンパイル時間 | 7,245 ms | 
| コンパイル使用メモリ | 334,460 KB | 
| 実行使用メモリ | 12,660 KB | 
| 最終ジャッジ日時 | 2025-06-30 21:17:20 | 
| 合計ジャッジ時間 | 15,853 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 53 WA * 17 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define NP next_permutation
const int INF32 = 2e9;
const ll INF64 = 2e18;
const ll mod = 998244353;
// const ll mod = 1e9 + 7;
template<typename T> bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
 
void cincout() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
}
 
int main() {
    cincout();
 
    int N, M, K;
    cin >> N >> M >> K;
    
    vector<int> C(M);
    for (int i = 0; i < M; i++) cin >> C[i];
    using P = pair<ll, ll>;
    vector<vector<P>> graph(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        graph[u].emplace_back(v, C[i]);
        graph[v].emplace_back(u, C[i]);
    }
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, 0});
    vector<ll> dist(N, INF64);
    dist[0] = 0;
    while (!pq.empty()) {
        auto [d, v] = pq.top(); 
        pq.pop();
        if (dist[v] < d) continue;
        for (auto [next_v, w] : graph[v]) {
            if (chmin(dist[next_v], d + w)) pq.emplace(dist[next_v], next_v);
        } 
    }
    if (dist[N - 1] == INF64) {
        cout << -1 << endl;
        return 0;
    }
    
    vector<ll> max_w;
    int v = N - 1;
    while (v != 0) {
        for (auto [prev_v, w] : graph[v]) {
            if (dist[prev_v] + w == dist[v]) {
                max_w.push_back(w);
                v = prev_v;
                break;
            }
        }
    }
    sort(rall(max_w));
    ll sum = 0;
    for (int i = 0; i < min(K, (int)max_w.size()); i++) sum += max_w[i];
    cout << dist[N - 1] - sum << endl;
}
            
            
            
        