結果

問題 No.2202 贅沢てりたまチキン
ユーザー umimelumimel
提出日時 2023-02-03 21:31:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 168,152 KB
実行使用メモリ 9,448 KB
最終ジャッジ日時 2023-09-15 16:58:37
合計ジャッジ時間 3,749 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 6 ms
9,272 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 44 ms
9,448 KB
testcase_15 AC 43 ms
9,224 KB
testcase_16 AC 36 ms
9,288 KB
testcase_17 AC 36 ms
9,236 KB
testcase_18 AC 19 ms
6,180 KB
testcase_19 AC 25 ms
9,392 KB
testcase_20 AC 46 ms
9,228 KB
testcase_21 AC 45 ms
9,176 KB
testcase_22 AC 30 ms
4,380 KB
testcase_23 AC 34 ms
4,380 KB
testcase_24 AC 33 ms
4,380 KB
testcase_25 AC 70 ms
9,328 KB
testcase_26 AC 43 ms
9,284 KB
testcase_27 AC 43 ms
9,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

struct UnionFind{
    vector<ll> parent;
    vector<ll> sizes;
    
    UnionFind(ll N) : parent(N), sizes(N, 1){
        rep(i, N) parent[i] = i;
    }
    
    ll root(ll x){
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }
 
    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if (sizes[rx] < sizes[ry]) swap(rx, ry);
        sizes[rx] += sizes[ry];
        parent[ry] = rx;
    }
 
    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
 
    ll size(ll x){
        return sizes[root(x)];
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, m;
    cin >> n >> m;

    UnionFind UF(2*n);
    rep(i, m){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        UF.unite(a, n+b);
        UF.unite(n+a, b);
    }

    bool flag = true;
    rep(i, n){
        if(!UF.same(i, n+i)) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}
0