結果

問題 No.2948 move move rotti
ユーザー nonon
提出日時 2024-10-26 08:59:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 192 ms / 4,000 ms
コード長 1,351 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 259,776 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-26 09:00:09
合計ジャッジ時間 6,185 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> X(K);
    for (int i = 0; i < K; i++) {
        cin >> X[i];
        X[i]--;
    }
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<vector<long long>> bs(K, vector<long long>(N, 0));
    for (int i = 0; i < K; i++) {
        vector<vector<bool>> dp(1 << N, vector<bool>(N, false));
        dp[1 << X[i]][X[i]] = true;
        for (int bit = 0; bit < 1 << N; bit++) {
            for (int u = 0; u < N; u++) {
                if (!dp[bit][u]) continue;
                bs[i][u] |= 1LL << __builtin_popcount(bit);
                for (int v : G[u]) {
                    if ((bit >> v & 1) == 0) {
                        dp[bit ^ (1 << v)][v] = true;
                    }
                }
            }
        }
    }
    for (int t = 0; t < N; t++) {
        long long bs_all = 0;
        bs_all = ~bs_all;
        for (int i = 0; i < K; i++) {
            bs_all &= bs[i][t];
        }
        if (__builtin_popcountll(bs_all)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0