結果

問題 No.1812 Uribo Road
ユーザー KudeKude
提出日時 2022-01-14 22:38:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,692 bytes
コンパイル時間 2,992 ms
コンパイル使用メモリ 247,020 KB
実行使用メモリ 814,364 KB
最終ジャッジ日時 2024-04-30 16:12:28
合計ジャッジ時間 7,616 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 30 ms
10,112 KB
testcase_04 AC 2 ms
6,944 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 563 ms
326,144 KB
testcase_09 MLE -
testcase_10 AC 590 ms
343,936 KB
testcase_11 AC 202 ms
109,184 KB
testcase_12 MLE -
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>;


template<class T>
std::vector<unsigned int> dijkstra(const std::vector<std::vector<std::pair<int,T>>>& to, int s=0) {
    const unsigned int INF = 2001001001;
    struct QueElem {
        int v;
        unsigned int c;
        bool operator<(const QueElem a) const {return c > a.c;}
        QueElem(int v, unsigned int c): v(v), c(c) {}
    };
    std::priority_queue<QueElem> q;
    std::vector<unsigned int> 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 int c = qe.c;
        if (c > dist[u]) continue;
        for(auto vc: to[u]) {
            int v = vc.first;
            unsigned int 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--;
    ps.emplace_back(a);
    ps.emplace_back(b);
    to1[a].emplace_back(b, c);
    to1[b].emplace_back(a, c);
    if (nxt < k && i == r[nxt]) {
      es[nxt++] = {a, b, c};
    }
  }
  sort(all(ps));
  ps.erase(unique(all(ps)), ps.end());
  int sz = ps.size();
  vector<vector<P>> to2(sz << k);
  rep(i, sz) {
    auto d = dijkstra(to1, ps[i]);
    rep(j, sz) {
      int c = d[ps[j]];
      rep(s, 1 << k) to2[s | i << k].emplace_back(s | j << k, c);
    }
  }
  rep(i, k) {
    auto [u, v, c] = es[i];
    int ui = lower_bound(all(ps), u) - ps.begin();
    int vi = lower_bound(all(ps), v) - ps.begin();
    rep(s, 1 << k) {
      int ns = s | 1 << i;
      to2[s | ui << k].emplace_back(ns | vi << k, c);
      to2[s | vi << k].emplace_back(ns | ui << k, c);
    }
  }
  auto d = dijkstra(to2);
  cout << d.back() << '\n';
}
0