結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2025-04-19 17:19:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 208 ms / 5,000 ms |
| コード長 | 2,686 bytes |
| コンパイル時間 | 1,899 ms |
| コンパイル使用メモリ | 171,068 KB |
| 実行使用メモリ | 19,852 KB |
| 最終ジャッジ日時 | 2025-04-19 17:19:49 |
| 合計ジャッジ時間 | 9,989 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 70 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, M, K;
ll C[101010];
vector<pair<int,ll>> E[101010];
int vis[101010][4];
ll D[101010][4];
void _main() {
cin >> N >> M >> K;
rep(i, 0, M) cin >> C[i];
rep(i, 0, M) {
int a, b;
cin >> a >> b;
a--; b--;
E[a].push_back({ b, C[i] });
E[b].push_back({ a, C[i] });
}
rep(town, 0, N) rep(coupon, 0, K + 1) D[town][coupon] = infl;
rep(town, 0, N) rep(coupon, 0, K + 1) vis[town][coupon] = 0;
min_priority_queue<pair<ll, pair<int,int>>> que;
D[0][K] = 0;
que.push({ 0, {0, K} });
while (!que.empty()) {
auto q = que.top(); que.pop();
ll cst = q.first;
int town = q.second.first;
int coupon = q.second.second;
if (vis[town][coupon]) continue;
vis[town][coupon] = 1;
fore(p, E[town]) {
ll cst2 = cst + p.second;
int town2 = p.first;
// use coupon
if (coupon > 0) {
if (chmin(D[town2][coupon - 1], cst)) que.push({ D[town2][coupon - 1], { town2, coupon - 1 } });
}
// not use coupon
if (chmin(D[town2][coupon], cst2)) que.push({ D[town2][coupon], { town2, coupon } });
}
}
ll ans = infl;
rep(coupon, 0, K + 1) chmin(ans, D[N - 1][coupon]);
if (ans == infl) ans = -1;
cout << ans << endl;
}
はまやんはまやん