結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー KudeKude
提出日時 2024-02-16 21:48:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 481 ms / 2,500 ms
コード長 1,593 bytes
コンパイル時間 3,460 ms
コンパイル使用メモリ 280,008 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-02-16 21:48:33
合計ジャッジ時間 10,207 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
12,672 KB
testcase_01 AC 310 ms
23,552 KB
testcase_02 AC 396 ms
39,808 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 78 ms
8,320 KB
testcase_07 AC 314 ms
42,880 KB
testcase_08 AC 291 ms
38,528 KB
testcase_09 AC 340 ms
43,520 KB
testcase_10 AC 452 ms
43,520 KB
testcase_11 AC 450 ms
43,520 KB
testcase_12 AC 481 ms
43,520 KB
testcase_13 AC 452 ms
43,520 KB
testcase_14 AC 447 ms
43,520 KB
testcase_15 AC 143 ms
6,548 KB
testcase_16 AC 141 ms
6,548 KB
testcase_17 AC 142 ms
6,548 KB
testcase_18 AC 129 ms
14,848 KB
testcase_19 AC 232 ms
34,176 KB
testcase_20 AC 205 ms
28,672 KB
testcase_21 AC 265 ms
43,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
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) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
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;
  cin >> n >> m;
  vector<P> edge(m);
  for (auto& [a, b] : edge) cin >> a >> b, a--, b--;
  VI c(n);
  rep(i, n) cin >> c[i], c[i]--;
  VI w(10);
  rep(i, 10) cin >> w[i];
  vector<dsu> uf;
  uf.reserve(1 << 10);
  VL cost(1 << 10);
  rep(i, 10) cost[1 << i] = w[i];
  rep(s, 1 << 10) {
    cost[s] = cost[s & -s] + cost[s ^ (s & -s)];
    uf.emplace_back(n);
    for (auto [a, b] : edge) {
      if (s >> c[a] & 1 && s >> c[b] & 1) uf[s].merge(a, b);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    constexpr long long INF = 1002003004005006007;
    ll ans = INF;
    rep(s, 1 << 10) if (s >> c[u] & 1 && s >> c[v] & 1 && uf[s].same(u, v)) {
      chmin(ans, cost[s]);
    }
    if (ans == INF) ans = -1;
    cout << ans << '\n';
  }
}
0