結果

問題 No.2948 move move rotti
ユーザー t98slider
提出日時 2024-10-27 09:59:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 4,000 ms
コード長 983 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 197,780 KB
最終ジャッジ日時 2025-02-25 00:45:32
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k, U = 0;
    cin >> n >> m >> k;
    array<array<int,15>,32768> dp{};
    while(k--){
        int v;
        cin >> v;
        v--;
        U |= 1 << v;
        dp[1 << v][v] = 1 << v;
    }
    vector<vector<int>> G(n);
    while(m--){
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    array<array<int,15>,15> T{};
    for(int S = 0; S < (1 << n); S++){
        const int cnt = __builtin_popcount(S) - 1;
        for(int v = 0; v < n; v++){
            if(dp[S][v] == 0) continue;
            for(auto &&u : G[v]){
                if(S >> u & 1) continue;
                dp[S | (1 << u)][u] |= dp[S][v];
            }
            if(((T[cnt][v] |= dp[S][v]) & U) == U){
                cout << "Yes\n";
                exit(0);
            }
        }
    }
    cout << "No\n";
}
0