結果

問題 No.1812 Uribo Road
ユーザー simansiman
提出日時 2022-01-20 04:41:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,674 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 144,364 KB
実行使用メモリ 142,412 KB
最終ジャッジ日時 2024-05-02 20:10:41
合計ジャッジ時間 10,875 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 26 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 37 ms
5,376 KB
testcase_09 RE -
testcase_10 AC 28 ms
5,376 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Edge {
  int id;
  int u;
  ll cost;

  Edge(int id = -1, int u = -1, ll cost = -1) {
    this->id = id;
    this->u = u;
    this->cost = cost;
  }
};

vector<Edge> E[210];

struct Node {
  int v;
  int mask;
  ll cost;

  Node(int v = -1, int mask = -1, ll cost = -1) {
    this->v = v;
    this->mask = mask;
    this->cost = cost;
  }

  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

int main() {
  int N, M, K;
  cin >> N >> M >> K;

  vector<int> R(K);
  for (int i = 0; i < K; ++i) {
    cin >> R[i];
  }

  for (int i = 1; i <= M; ++i) {
    int a, b;
    ll c;
    cin >> a >> b >> c;

    E[a].push_back(Edge(i, b, c));
    E[b].push_back(Edge(i, a, c));
  }

  priority_queue <Node, vector<Node>, greater<Node>> pque;
  pque.push(Node(1, 0, 0));
  bool visited[2 << K][N + 1];
  memset(visited, false, sizeof(visited));
  ll ans = LLONG_MAX;

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (visited[node.mask][node.v]) continue;
    visited[node.mask][node.v] = true;

    if (node.v == N && node.mask == (1 << K) - 1) {
      ans = min(ans, node.cost);
      continue;
    }

    for (Edge &e : E[node.v]) {
      int nmask = node.mask;

      for (int k = 0; k < K; ++k) {
        if (e.id != R[k]) continue;
        nmask |= (1 << k);
      }

      pque.push(Node(e.u, nmask, node.cost + e.cost));
    }
  }

  cout << ans << endl;

  return 0;
}

0