結果

問題 No.2202 贅沢てりたまチキン
ユーザー ermineermine
提出日時 2023-02-03 22:08:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 205,192 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-09-15 18:01:10
合計ジャッジ時間 4,877 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,500 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 5 ms
6,160 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 112 ms
6,140 KB
testcase_15 AC 111 ms
6,216 KB
testcase_16 AC 87 ms
6,244 KB
testcase_17 AC 89 ms
6,192 KB
testcase_18 AC 43 ms
4,580 KB
testcase_19 AC 59 ms
6,152 KB
testcase_20 AC 116 ms
6,340 KB
testcase_21 AC 116 ms
6,304 KB
testcase_22 AC 77 ms
4,380 KB
testcase_23 AC 91 ms
4,380 KB
testcase_24 AC 83 ms
4,380 KB
testcase_25 AC 125 ms
6,204 KB
testcase_26 AC 112 ms
6,188 KB
testcase_27 AC 113 ms
6,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


struct UnionFind {
    vector<int> _parent, _size;

    UnionFind(int n) {
        _parent.resize(n);
        _size.resize(n, 1);
        for(int i=0; i<n; i++) _parent[i] = i;
    }

    int find(int x) {
        if (_parent[x] == x) return x;
        return _parent[x] = find(_parent[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) return false;
        if (_size[x] < _size[y]) swap(x, y);
        _parent[y] = x;
        _size[x] += _size[y];

        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return _size[find(x)]; }
};


int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n*2);

    vector<vector<int>> g1,g2;
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;
        a--; b--;
        uf.unite(a,b+n);
        uf.unite(a+n,b);
    }

    bool ok=true;
    for(int i=0; i<n; i++){
        if(!uf.same(i,i+n)) ok=false;
    }

    cout<<(ok?"Yes":"No")<<endl;
}
0