結果

問題 No.408 五輪ピック
コンテスト
ユーザー yantaro
提出日時 2026-04-20 18:16:44
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 3,543 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,326 ms
コンパイル使用メモリ 224,000 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-20 18:16:50
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
//python3 expander.py main.cpp

using ll = long long;
using ld = long double;
using lll = __int128_t;

//using mint = modint; //mint::set_mod(M);
//using mint = modint998244353;
//using mint = modint1000000007;

template<class T> using pq = priority_queue<T>; //大きい順
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>; //小さい順

#define vec_unique(v) v.erase(unique(v.begin(), v.end()), v.end()) //重複削除
#define vec_iota(v) iota(v.begin(), v.end(), 0) //0, 1, 2, 3, ..., n - 1にセット
#define concat(a, b) a.insert(a.end(), b.begin(), b.end())
#define debug(x) cerr << #x << " = " << x << endl
#define maxvalue(array) *max_element(array.begin(), array.end())
#define minvalue(array) *min_element(array.begin(), array.end())
#define sumvalue(array) accumulate(array.begin(), array.end(), 0ll)
#define popcount(x) __builtin_popcountll(x)

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define INF 2e18
#define INF2 2e9

// std::uniform_int_distributionを利用した一様乱数生成クラス
class Random_Gen{
    random_device seed_gen;
    mt19937 engine;
    uniform_int_distribution<int64_t> dist;
    public:
        // Constructor [l,r]で生成する値の範囲を指定
        Random_Gen() : engine(seed_gen()) {}
        Random_Gen(int64_t l, int64_t r) : engine(seed_gen()), dist(l,r) {}
        
        // 現在の生成する値の範囲をstd::pairで返す
        pair<int64_t,int64_t> get_range(){
            return make_pair(dist.min(),dist.max());
        }
        // 生成する値の範囲を[l,r]に変更する
        void set_range(int64_t l, int64_t r){
            uniform_int_distribution<int64_t>::param_type Param(l,r);
            dist.param(Param);
        }
        // [l,r]内の一様分布の整数を返す
        int64_t gen(){
            return dist(engine);
        }
        int64_t operator()(){ return gen(); }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    vector<bitset<500>> bs(500);
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    Random_Gen Random(0, 4);

    auto f = [&]() -> bool {
        vector<int> color(n);
        for(int i = 0; i < n; i++) color[i] = Random.gen();

        vector<vector<bool>> dp((1 << 5), vector<bool>(n));
        dp[(1 << color[0])][0] = true;

        for(int i = 0; i < (1 << 5); i++) {
            for(int j = 0; j < n; j++) {
                if(!dp[i][j]) continue;

                for(auto next_v : graph[j]) {
                    int c = color[next_v];
                    if(!(i & (1 << c))) {
                        dp[i | (1 << c)][next_v] = true;
                    }
                }
            }
        }

        for(int i = 0; i < n; i++) {
            if(dp[(1 << 5) - 1][i]) {
                for(auto next_v : graph[i]) {
                    if(next_v == 0) return true;
                }
            }
        }

        return false;
    };

    for(int iter = 0; iter < 200; iter++) {
        if(f()) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    //cout << fixed << setprecision(15) << << endl;
    return 0;
}
0