結果

問題 No.1812 Uribo Road
ユーザー KudeKude
提出日時 2022-01-14 22:21:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,979 bytes
コンパイル時間 2,755 ms
コンパイル使用メモリ 239,148 KB
実行使用メモリ 334,992 KB
最終ジャッジ日時 2024-04-30 15:36:14
合計ジャッジ時間 9,096 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 8 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 16 ms
6,940 KB
testcase_09 AC 31 ms
6,944 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 7 ms
6,940 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 #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<class T> void chmin(T& a, const T& b) { a = min(a, b); }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  // [state][v]
  struct Edge {
    int to;
    int c;
    int k;
  };
  vector<vector<Edge>> to(n);
  VI r(k);
  rep(i, k) cin >> r[i], r[i]--;
  sort(all(r));
  int nxt = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    if (nxt < k && r[nxt] == i) {
      to[a].emplace_back(Edge{b, c, nxt});
      to[b].emplace_back(Edge{a, c, nxt});
      nxt++;
    } else {
      to[a].emplace_back(Edge{b, c, -1});
      to[b].emplace_back(Edge{a, c, -1});
    }
  }
  assert(nxt == k);
  constexpr ll INF = 1002003004005006007;
  vector<ll> dist(n << k, INF);
  auto cmp = [](const pair<int, ll>& x, const pair<int, ll>& y) {
    return x.second > y.second;
  };
  priority_queue<pair<int, ll>, vector<pair<int, ll>>, decltype(cmp)> q(cmp);
  auto push = [&](int s, int v, ll d) {
    int idx = s | v << k;
    if (d < dist[idx]) {
      dist[idx] = d;
      q.emplace(idx, d);
    }
  };
  push(0, 0, 0);
  while(!q.empty()) {
    auto [idx, d] = q.top(); q.pop();
    if (dist[idx] != d) continue;
    int u = idx >> k;
    int s = idx & (1 << k) - 1;
    for(auto [v, c, b] : to[u]) {
      int ns = b != -1 ? s | 1 << b : s;
      push(ns, v, d + c);
    }
  }
  cout << dist.back() << '\n';
}
0