結果

問題 No.3111 Toll Optimization
ユーザー lk step
提出日時 2025-04-18 21:57:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 1,984 ms
コンパイル使用メモリ 202,692 KB
実行使用メモリ 21,000 KB
最終ジャッジ日時 2025-04-18 21:58:06
合計ジャッジ時間 9,482 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 48 WA * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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)) );
        } 
      }
    }
  }
            
  cout<<ans<<endl;
  return 0;
}

0