結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-04-18 21:54:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,312 bytes |
コンパイル時間 | 2,352 ms |
コンパイル使用メモリ | 202,868 KB |
実行使用メモリ | 15,136 KB |
最終ジャッジ日時 | 2025-04-18 21:54:32 |
合計ジャッジ時間 | 10,514 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 5 TLE * 1 -- * 64 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> edge; typedef pair<ll,edge> Data; const ll INF = (1LL<<60); ll ans=INF; ll N,M,K; vector<edge> g[100000]; ll d[100000][4]; ll cost[100000]; int main(){ cin>>N>>M>>K; for(int i=0;i<M;i++)cin>>cost[i]; for(int i=0;i<M;i++){ ll a,b; cin>>a>>b; a--,b--; g[a].push_back( edge(b,cost[i]) ); g[b].push_back( edge(a,cost[i]) ); } for(int i=0;i<N;i++){ for(int j=0;j<=K;j++){ d[i][j]=INF; } } priority_queue< Data, vector<Data>, greater<Data> > que; que.push( Data(0,edge(0,K) ) ); d[0][K]=0; while(!que.empty()){ Data dat = que.top(); que.pop(); ll pos = dat.second.first; ll tk = dat.second.second; ll cost = dat.first; if(pos==N-1)ans=min(ans,cost); if(d[pos][tk]>cost)continue; for(int i=0;i<(int)g[pos].size();i++){ ll to = g[pos][i].first; ll ncost = cost + g[pos][i].second; if( d[to][tk] > ncost ){ d[to][tk]=ncost; que.push( Data(ncost,edge(to,tk)) ); } ll nk=tk-1; if(nk>=0){ if( d[to][nk] > cost ){ d[to][nk]=cost; que.push( Data(cost,edge(to,nk)) ); } } } } cout<<ans<<endl; return 0; }