結果
| 問題 | No.3111 Toll Optimization | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-09-11 19:01:52 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,066 bytes | 
| コンパイル時間 | 6,929 ms | 
| コンパイル使用メモリ | 266,948 KB | 
| 実行使用メモリ | 22,940 KB | 
| 最終ジャッジ日時 | 2025-09-11 19:02:37 | 
| 合計ジャッジ時間 | 43,413 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 67 TLE * 3 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101010;
int n, m, k;
int c[maxn];
vector<pair<int,int>> g[maxn];
long dp[4][maxn];
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin >> n >> m >> k;
	for(int i = 0; i < m; i++) cin >> c[i];
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back({b,c[i]});
		g[b].push_back({a,c[i]});
	}
	memset(dp,0x01,sizeof(dp));
	dp[0][0] = 0;
	priority_queue<pair<long, int>, vector<pair<long,int>>, greater<pair<long,int>>> pq;
	pq.push({0, 0});
	while(!pq.empty()) {
		auto[e,foo] = pq.top();
		pq.pop();
		int v = foo / 4, t = foo % 4;
		for(auto[u, cst]: g[v]) {
			if(t + 1 <= k) {
				if(dp[t + 1][u] > dp[t][v]) {
					dp[t + 1][u] = dp[t][v];
					pq.push({dp[t + 1][u], u*4+t+1});
				}
			}
			if(dp[t][u]>dp[t][v]+cst) {
				dp[t][u]=dp[t][v]+cst;
				pq.push({dp[t][u],u*4+t});
			}
		}
	}
	long ans = 3467192473289423;
	for(int i = 0; i <= k; i++) ans = min(ans, dp[i][n-1]);
	if(ans==3467192473289423) ans = -1;
	cout << ans << "\n";
}
            
            
            
        