結果

問題 No.1812 Uribo Road
ユーザー tnakao0123tnakao0123
提出日時 2022-01-16 00:56:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,536 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 61,244 KB
実行使用メモリ 334,728 KB
最終ジャッジ日時 2024-05-02 00:05:27
合計ジャッジ時間 7,567 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 19 ms
6,940 KB
testcase_09 AC 38 ms
6,948 KB
testcase_10 AC 13 ms
6,940 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
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 #

/* -*- coding: utf-8 -*-
 *
 * 1812.cc:  No.1812 Uribo Road - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_M = 20000;
const int MAX_K = 12;
const int KBITS = 1 << MAX_K;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
int ebs[MAX_M], cs[MAX_M];
ll ds[MAX_N * KBITS];

/* subroutines */

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int kbits = 1 << k, kmsk = kbits - 1;

  for (int i = 0; i < k; i++) {
    int ri;
    scanf("%d", &ri), ri--;
    ebs[ri] = 1 << i;
  }

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d%d", &u, &v, cs + i);
    u--, v--;
    nbrs[u].push_back(pii(v, i));
    nbrs[v].push_back(pii(u, i));
  }

  fill(ds, ds + n * kbits, LINF);
  ds[0] = 0;

  priority_queue<pli> q;
  q.push(pli(0, 0));

  int gl = (n - 1) << k | kmsk;

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    int up = u.second;
    if (ds[up] != ud) continue;
    if (up == gl) break;

    int ui = up >> k, ub = up & kmsk;
    for (auto ve: nbrs[ui]) {
      int vi = ve.first, ei = ve.second;
      int vb = ub | ebs[ei];
      int vp = vi << k | vb;
      ll vd = ud + cs[ei];

      if (ds[vp] > vd) {
	ds[vp] = vd;
	q.push(pli(-vd, vp));
      }
    }
  }

  printf("%lld\n", ds[gl]);
  return 0;
}
0