結果

問題 No.1812 Uribo Road
ユーザー miscalcmiscalc
提出日時 2022-01-14 23:08:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,243 bytes
コンパイル時間 2,664 ms
コンパイル使用メモリ 217,816 KB
実行使用メモリ 814,892 KB
最終ジャッジ日時 2024-11-20 13:57:32
合計ジャッジ時間 27,179 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 27 ms
8,832 KB
testcase_04 AC 2 ms
6,820 KB
testcase_05 AC 2 ms
6,820 KB
testcase_06 AC 2 ms
6,816 KB
testcase_07 AC 3 ms
6,816 KB
testcase_08 AC 48 ms
11,520 KB
testcase_09 AC 104 ms
18,432 KB
testcase_10 AC 41 ms
10,368 KB
testcase_11 AC 16 ms
6,816 KB
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 AC 865 ms
130,784 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 AC 217 ms
31,392 KB
testcase_24 AC 2 ms
6,816 KB
testcase_25 AC 23 ms
6,816 KB
testcase_26 AC 16 ms
7,552 KB
testcase_27 MLE -
testcase_28 AC 49 ms
8,320 KB
testcase_29 AC 2 ms
6,816 KB
testcase_30 AC 115 ms
38,144 KB
testcase_31 MLE -
testcase_32 AC 34 ms
12,288 KB
testcase_33 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
//using mint = modint998244353;
using mint = modint1000000007;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
//constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {return (A % M + M) % M;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

constexpr int INF = 1LL << 30;
template<class T> class graph
{
public:
  struct edge
  {
    ll to;
    T cost;
    edge(ll to, T cost) : to(to), cost(cost) {}
  };

  ll N;
  vector<vector<edge>> G;

  graph(ll n)
  {
    N = n;
    G.resize(N);
  }

  void connect(ll sv, ll gv, T c)
  {
    G.at(sv).push_back(edge(gv, c));
  }

  void connect2(ll v0, ll v1, T c)
  {
    connect(v0, v1, c), connect(v1, v0, c);
  }

  vector<T> _01bfs(ll sv)
  {
    vector<T> costs(N, INF);
    costs.at(sv) = 0;
    deque<tuple<T, ll, ll>> deq;
    for (auto e : G.at(sv))
    {
      if (e.cost == 0)
        deq.push_front(make_tuple(e.cost, sv, e.to));
      else
        deq.push_back(make_tuple(e.cost, sv, e.to));
    }

    while (!deq.empty())
    {
      auto [c, pv, v] = deq.front();
      deq.pop_front();

      if (chmin(costs.at(v), costs.at(pv) + c))
      {
        for (auto e : G.at(v))
        {
          if (e.cost == 0)
            deq.push_front(make_tuple(e.cost, v, e.to));
          else
            deq.push_back(make_tuple(e.cost, v, e.to));
        }
      }
    }
    return costs;
  }

  vector<T> dijkstra(ll sv)
  {
    vector<T> costs(N, INF);
    costs.at(sv) = 0;
    priority_queue<pair<T, ll>, vector<pair<T, ll>>, greater<pair<T, ll>>> pque;
    pque.emplace(make_pair(0, sv));

    while (!pque.empty())
    {
      auto [c, v] = pque.top();
      pque.pop();

      if (costs.at(v) < c)
        continue;
      
      for (auto e : G.at(v))
      {
        T nc = c + e.cost;
        if (costs.at(e.to) > nc)
        {
          costs.at(e.to) = nc;
          pque.emplace(nc, e.to);
        }
      }
    }
    return costs;
  }
};

ll ptol(ll i, ll bt, ll K)
{
  return i * (1LL << K) + bt;
}

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

  vector<ll> invR(M, -1);
  for (ll i = 0; i < K; i++)
  {
    ll r;
    cin >> r;
    r--;
    invR.at(r) = i;
  }

  graph<int> gr(N * (1LL << K));
  for (ll i = 0; i < M; i++)
  {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;

    for (ll bt = 0; bt < (1LL << K); bt++)
    {
      ll nbt = bt;
      if (invR.at(i) != -1)
        nbt |= (1LL << invR.at(i));

      ll u = ptol(a, bt, K), nu = ptol(b, nbt, K);
      ll v = ptol(b, bt, K), nv = ptol(a, nbt, K);
      gr.connect(u, nu, c);
      gr.connect(v, nv, c);
    }
  }
 
  ll sv = ptol(0, 0, K), gv = ptol(N - 1, (1LL << K) - 1, K);
  auto dists = gr.dijkstra(sv);
  ll ans = dists.at(gv);
  cout << ans << endl;
}
0