結果

問題 No.2948 move move rotti
ユーザー Nzt3Nzt3
提出日時 2024-10-25 21:52:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 242 ms / 4,000 ms
コード長 1,230 bytes
コンパイル時間 3,505 ms
コンパイル使用メモリ 258,368 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2024-10-25 21:52:29
合計ジャッジ時間 7,786 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, l, r) for (int i = (l); i < (int)(r); i++)
#define all(v) v.begin(), v.end()
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M,K;
  cin>>N>>M>>K;
  vector G(N,vector(N,0));
  vector X(K,0);
  for(int &i:X)cin>>i,--i;
  rep(i,M){
    int U,V;
    cin>>U>>V;
    --U,--V;
    G[U][V]=1;
    G[V][U]=1;
  }
  vector dp(1<<N,vector(N,vector(N,false)));
  rep(i,N){
    dp[1<<i][i][i]=1;
  }
  rep(s,1<<N){
    rep(i,N){
      if(!(s>>i&1))continue;
      rep(v1,N){
        if(!dp[s][i][v1])continue;
        rep(v2,N){
          if(!G[v1][v2])continue;
          if(s>>v2&1)continue;
          dp[s|(1<<v2)][i][v2]=1;
        }
      }
    }
  }
  vector ok(N,vector(N,vector(N,false)));
  rep(s,1<<N){
    rep(i,N){
      rep(j,N){
        if(dp[s][i][j]){
          ok[i][j][__builtin_popcount(s)]=1;
        }
      }
    }
  }
  bool yes=0;
  rep(i,N){
    rep(j,N){
      bool now=1;
      for(int k:X){
        if(!ok[k][i][j])now=0;
      }
      if(now)yes=1;
    }
  }
  cout<<(yes?"Yes\n":"No\n");
}
0