結果

問題 No.1 道のショートカット
ユーザー knkknk
提出日時 2017-09-24 20:45:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,743 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 98,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:11:29
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>
#include <queue>

typedef long long ll;
// time, city, cost
typedef std::tuple< int, int, int, std::vector< bool > > node;

int main(void)
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(13);
  int n, c, v;
  std::cin >> n >> c >> v;
  std::vector< std::vector< std::tuple< int, int, int > > > path(n);
  int s[v], t[v], y[v], m[v];
  for (int i = 0; i < v; ++i) std::cin >> s[i];
  for (int i = 0; i < v; ++i) std::cin >> t[i];
  for (int i = 0; i < v; ++i) std::cin >> y[i];
  for (int i = 0; i < v; ++i) std::cin >> m[i];
  for (int i = 0; i < v; ++i) {
    s[i]--; t[i]--;
    path[s[i]].push_back(std::make_tuple(t[i], y[i], m[i]));
  }
  std::vector< bool > visited(n);
  std::fill(visited.begin(), visited.end(), false);
  visited[0] = true;
  node root = make_tuple(0, 0, 0, visited);
  std::priority_queue< node, std::vector< node >, std::greater< node > > q;
  q.push(root);
  while (!q.empty()) {
    auto prev = q.top();
    q.pop();
    int ptime = std::get<0>(prev), pcity = std::get<1>(prev), pcost = std::get<2>(prev);
    if (pcity == n-1) {
      std::cout << ptime << std::endl;
      return 0;
    }
    std::vector< bool > pvisited = std::get<3>(prev);
    for (auto next : path[pcity]) {
      int path_to = std::get<0>(next), path_cost = std::get<1>(next), path_time = std::get<2>(next);
      if (pvisited[path_to] || pcost + path_cost > c) continue;
      pvisited[path_to] = true;
      node next_node = make_tuple(ptime + path_time, path_to, pcost + path_cost, pvisited);
      q.push(next_node);
      pvisited[path_to] = false;
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}
0