結果

問題 No.2202 贅沢てりたまチキン
ユーザー irohasu19_irohasu19_
提出日時 2023-03-11 15:59:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 2,438 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 205,356 KB
実行使用メモリ 12,832 KB
最終ジャッジ日時 2023-10-18 09:59:49
合計ジャッジ時間 6,142 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 8 ms
12,832 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 124 ms
12,832 KB
testcase_15 AC 124 ms
12,832 KB
testcase_16 AC 99 ms
12,832 KB
testcase_17 AC 100 ms
12,832 KB
testcase_18 AC 50 ms
8,148 KB
testcase_19 AC 67 ms
12,832 KB
testcase_20 AC 129 ms
12,832 KB
testcase_21 AC 128 ms
12,832 KB
testcase_22 AC 84 ms
4,348 KB
testcase_23 AC 99 ms
4,348 KB
testcase_24 AC 91 ms
4,348 KB
testcase_25 AC 175 ms
12,832 KB
testcase_26 AC 126 ms
12,832 KB
testcase_27 AC 126 ms
12,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
#define repr(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,n) for(int i=0;i<n;i++) 
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b) 
#define reprev(i,n) reprrev(i,0,n) 
#define _GLIBCXX_DEBUG 
#define int long long         
using ll = long long; 
using ull = unsigned long long; 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } 
const ll mod = 1e9+7; 
void chmod(ll &M){ 
  if(M >= mod) M %= mod; 
  else if(M < 0){ 
     M += (abs(M)/mod + 1)*mod; 
    M %= mod; 
} 
} 

int getl(int i, int N) { return i==0? N-1:i-1; }; 
int getr(int i, int N) { return i==N-1? 0:i+1; }; 
long long GCD(long long a, long long b) { 
  if (b == 0) return a; 
  else return GCD(b, a % b); 
} 
using namespace std; 
using Graph = vector<vector<int>>;
// Union-Find
struct UnionFind {
    vector<int> par, rank, siz;

    // 構造体の初期化
    UnionFind(int n) : par(n,-1), rank(n,0), siz(n,1) { }

    // 根を求める
    int root(int x) {
        if (par[x]==-1) return x; // x が根の場合は x を返す
        else return par[x] = root(par[x]); // 経路圧縮
    }

    // x と y が同じグループに属するか (= 根が一致するか)
    bool issame(int x, int y) {
        return root(x)==root(y);
    }

    // x を含むグループと y を含むグループを併合する
    bool unite(int x, int y) {
        int rx = root(x), ry = root(y); // x 側と y 側の根を取得する
        if (rx==ry) return false; // すでに同じグループのときは何もしない
        // union by rank
        if (rank[rx]<rank[ry]) swap(rx, ry); // ry 側の rank が小さくなるようにする
        par[ry] = rx; // ry を rx の子とする
        if (rank[rx]==rank[ry]) rank[rx]++; // rx 側の rank を調整する
        siz[rx] += siz[ry]; // rx 側の siz を調整する
        return true;
    }

    // x を含む根付き木のサイズを求める
    int size(int x) {
        return siz[root(x)];
    }
};
signed main() {
  int n, m; cin >> n >> m;
  UnionFind tree(2*n);
  rep(i, m) {
    int a, b; cin >> a >> b; a--; b--;
    tree.unite(a, b+n);
    tree.unite(a+n, b);
  }
  
  rep(i, n) {
    if(tree.issame(i, i+n)==false) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}
0