結果

問題 No.3111 Toll Optimization
コンテスト
ユーザー lk step
提出日時 2025-04-18 21:57:55
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,357 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,264 ms
コンパイル使用メモリ 219,712 KB
実行使用メモリ 19,068 KB
最終ジャッジ日時 2026-07-09 19:11:19
合計ジャッジ時間 7,383 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 48 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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