結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー Kude
提出日時 2024-02-16 21:48:20
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 425 ms / 2,500 ms
コード長 1,593 bytes
コンパイル時間 3,015 ms
コンパイル使用メモリ 279,696 KB
実行使用メモリ 43,392 KB
最終ジャッジ日時 2024-09-28 20:02:48
合計ジャッジ時間 8,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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