結果

問題 No.408 五輪ピック
ユーザー yuppe19 😺yuppe19 😺
提出日時 2019-09-22 22:48:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,644 ms / 5,000 ms
コード長 969 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 79,616 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-09-19 03:46:35
合計ジャッジ時間 12,045 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using u64 = uint64_t;

u64 ux = time(NULL);
u64 gen() {
  ux = ux * 0x5d588b656c078965 + 0x269ec3;
  return ux;
}

int main(void) {
  int N, M; scanf("%d%d", &N, &M);
  vector<vector<int>> G(N, vector<int>());
  for(int i=0; i<M; ++i) {
    int a, b; scanf("%d%d", &a, &b);
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> col(N);
  vector<vector<bool>> dp;
  for(int loop=0; loop<300; ++loop) {
    for(int i=0; i<N; ++i) {
      col[i] = static_cast<int>(gen() % 5);
    }
    dp.assign(N, vector<bool>(1<<5, false));
    dp[0][0] = true;
    for(int S0=0; S0<1<<5; ++S0) {
      for(int u=0; u<N; ++u) {
        if(!dp[u][S0]) { continue; }
        for(int &v : G[u]) {
          if(S0 >> col[v] & 1) { continue; }
          dp[v][S0|(1<<col[v])] = true;
        }
      }
    }
    if(dp[0][(1<<5)-1]) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}
0