結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-04-18 21:59:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 201 ms / 5,000 ms |
コード長 | 1,371 bytes |
コンパイル時間 | 2,300 ms |
コンパイル使用メモリ | 201,896 KB |
実行使用メモリ | 20,484 KB |
最終ジャッジ日時 | 2025-04-18 22:00:05 |
合計ジャッジ時間 | 9,646 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | scanf("%lld %lld %lld",&N,&M,&K); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:20:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | for(int i=0;i<M;i++)scanf("%lld",&cost[i]); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%lld %lld",&a,&b); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#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(){ scanf("%lld %lld %lld",&N,&M,&K); for(int i=0;i<M;i++)scanf("%lld",&cost[i]); for(int i=0;i<M;i++){ ll a,b; scanf("%lld %lld",&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)) ); } } } } if(ans==INF)ans=-1; cout<<ans<<endl; return 0; }