結果

問題 No.3111 Toll Optimization
ユーザー テナガザル
提出日時 2025-04-19 01:49:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 522 ms / 5,000 ms
コード長 1,138 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 117,128 KB
実行使用メモリ 39,748 KB
最終ジャッジ日時 2025-04-19 01:49:23
合計ジャッジ時間 16,468 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> c(m);
  for (int i = 0; i < m; ++i) cin >> c[i];
  vector<vector<pair<int, int>>> g((k + 1) * n);
  for (int i = 0; i < m; ++i)
  {
    int a, b;
    cin >> a >> b;
    --a, --b;
    for (int j = 0; j <= k; ++j)
    {
      g[a * (k + 1) + j].emplace_back(b * (k + 1) + j, c[i]);
      g[b * (k + 1) + j].emplace_back(a * (k + 1) + j, c[i]);
    }
    for (int j = 0; j < k; ++j)
    {
      g[a * (k + 1) + j].emplace_back(b * (k + 1) + j + 1, 0);
      g[b * (k + 1) + j].emplace_back(a * (k + 1) + j + 1, 0);
    }
  }
  priority_queue<pair<long long, int>> pq;
  vector<long long> dis((k + 1) * n, 1e18);
  pq.emplace(0, 0);
  while (!pq.empty())
  {
    auto [d, now] = pq.top();
    pq.pop();
    d = -d;
    if (d >= dis[now]) continue;
    dis[now] = d;
    for (auto [to, c] : g[now]) pq.emplace(-d - c, to);
  }
  long long ans = 1e18;
  for (int i = 0; i <= k; ++i) ans = min(ans, dis[(n - 1) * (k + 1) + i]);
  if (ans >= 1e18) ans = -1;
  cout << ans << endl;
}
0