結果

問題 No.1812 Uribo Road
ユーザー KudeKude
提出日時 2022-01-14 23:23:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 3,385 bytes
コンパイル時間 3,036 ms
コンパイル使用メモリ 247,972 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-30 17:26:44
合計ジャッジ時間 4,345 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 35 ms
12,800 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 59 ms
13,696 KB
testcase_13 AC 36 ms
14,180 KB
testcase_14 AC 35 ms
14,176 KB
testcase_15 AC 24 ms
6,940 KB
testcase_16 AC 27 ms
6,940 KB
testcase_17 AC 72 ms
8,448 KB
testcase_18 AC 43 ms
13,184 KB
testcase_19 AC 102 ms
14,080 KB
testcase_20 AC 101 ms
14,208 KB
testcase_21 AC 95 ms
14,208 KB
testcase_22 AC 63 ms
14,080 KB
testcase_23 AC 8 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 10 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 20 ms
7,808 KB
testcase_28 AC 18 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 72 ms
13,696 KB
testcase_32 AC 4 ms
6,944 KB
testcase_33 AC 38 ms
13,312 KB
権限があれば一括ダウンロードができます

ソースコード

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>;


template<class T>
std::vector<unsigned long long> dijkstra(std::vector<std::vector<std::pair<int,T>>>& to, int s=0) {
    const unsigned long long INF = 1002003004005006007;
    struct QueElem {
        int v;
        unsigned long long c;
        bool operator<(const QueElem a) const {return c > a.c;}
        QueElem(int v, unsigned long long c): v(v), c(c) {}
    };
    std::priority_queue<QueElem> q;
    std::vector<unsigned long long> dist(to.size(), INF);
    dist[s] = 0;
    q.emplace(s, 0);
    while(!q.empty()) {
        QueElem qe = q.top(); q.pop();
        int u = qe.v;
        unsigned long long c = qe.c;
        if (c > dist[u]) continue;
        for(auto vc: to[u]) {
            int v = vc.first;
            unsigned long long nc = c + vc.second;
            if (nc < dist[v]) {
                dist[v] = nc;
                q.emplace(v, nc);
            }
        }
    }
    return dist;
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<P>> to1(n);
  VI r(k);
  rep(i, k) cin >> r[i], r[i]--;
  sort(all(r));
  VI ps{0, n - 1};
  vector<tuple<int, int, int>> es(k);
  int nxt = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    to1[a].emplace_back(b, c);
    to1[b].emplace_back(a, c);
    if (nxt < k && i == r[nxt]) {
      ps.emplace_back(a);
      ps.emplace_back(b);
      es[nxt++] = {a, b, c};
    }
  }
  sort(all(ps));
  ps.erase(unique(all(ps)), ps.end());
  int sz = ps.size();
  VVI dist0(sz, VI(sz));
  rep(i, sz) {
    auto d = dijkstra(to1, ps[i]);
    rep(j, sz) {
      int c = d[ps[j]];
      dist0[i][j] = c;
    }
  }
  rep(i, k) {
    auto& [u, v, c] = es[i];
    u = lower_bound(all(ps), u) - ps.begin();
    v = lower_bound(all(ps), v) - ps.begin();
  }

  vector<vector<P>> to2((1 << k) * k * 2 + 2);
  int s = (1 << k) * k * 2, t = s + 1;
  rep(i, k) {
    auto [u, v, c] = es[i];
    to2[s].emplace_back(1 << i | (2 * i + 1) << k, dist0[0][u] + c);
    to2[s].emplace_back(1 << i | (2 * i + 0) << k, dist0[0][v] + c);
    to2[(1 << k) - 1 | (2 * i + 0) << k].emplace_back(t, dist0[u][sz - 1]);
    to2[(1 << k) - 1 | (2 * i + 1) << k].emplace_back(t, dist0[v][sz - 1]);
  }
  rep(i, k) rep(b, 2) {
    int u = b == 0 ? get<0>(es[i]) : get<1>(es[i]);
    rep(s, 1 << k) if (s >> i & 1) {
      rep(j, k) if (!(s >> j & 1)) {
        int ns = s | 1 << j;
        int x = get<0>(es[j]);
        int y = get<1>(es[j]);
        to2[s | (2 * i + b) << k].emplace_back(ns | (2 * j + 0) << k, dist0[u][y] + get<2>(es[j]));
        to2[s | (2 * i + b) << k].emplace_back(ns | (2 * j + 1) << k, dist0[u][x] + get<2>(es[j]));
      }
    }
  }
  cout << dijkstra(to2, s)[t] << '\n';
}
0