結果
問題 | No.408 五輪ピック |
ユーザー |
|
提出日時 | 2023-01-27 14:29:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 468 ms / 5,000 ms |
コード長 | 1,332 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 178,496 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 01:12:24 |
合計ジャッジ時間 | 9,571 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; unsigned long long xor64(){ static unsigned long long x = 88172645463325252LL; x ^= (x << 13); x ^= (x >> 7); return (x ^= (x << 17)); } //頂点数Lの単純パスを見つける bool color_coding(vector<vector<int>> &g, int L){ int n = g.size(); vector<int> a(n); vector<vector<bool>> dp(1 << L, vector<bool>(n)); for(int i = 0; i < n; i++){ a[i] = 1 << (xor64() % L); } for(auto &&u:g[0]) dp[a[u]][u] = true; for(int S = 1; S < (1 << L); S++){ for(int v = 1; v < n; v++){ if(!dp[S][v])continue; for(auto &&u:g[v]){ if(!u || (S & a[u]))continue; dp[S | a[u]][u] = true; } } } for(auto &&u:g[0]) if(dp.back()[u])return true; return false; } int main(){ ios::sync_with_stdio(false); cin.tie(0); clock_t finish = clock() + CLOCKS_PER_SEC / 1000 * 460; int n, m, u, v; cin >> n >> m; vector<vector<int>> g(n); for(int i = 0; i < m; i++){ cin >> u >> v; g[--u].push_back(--v); g[v].push_back(u); } while(clock() <= finish){ if(color_coding(g, 4)){ cout << "YES" << '\n'; return 0; } } cout << "NO" << '\n'; }