結果
| 問題 |
No.2202 贅沢てりたまチキン
|
| コンテスト | |
| ユーザー |
Manuel1024
|
| 提出日時 | 2023-08-17 17:37:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 971 bytes |
| コンパイル時間 | 665 ms |
| コンパイル使用メモリ | 74,644 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-26 15:59:42 |
| 合計ジャッジ時間 | 4,090 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind{
vector<int> p;
UnionFind(int n): p(vector<int>(n, -1)){}
int root(int x){
if(p[x] < 0) return x;
else return p[x] = root(p[x]);
}
int size(int x){
return -p[root(x)];
}
bool same(int x, int y){
return root(x) == root(y);
}
void unite(int x, int y){
if(same(x, y)) return;
x = root(x);
y = root(y);
if(size(x) < size(y)) swap(x, y);
p[x] += p[y];
p[y] = x;
}
};
int main(){
int n, m; cin >> n >> m;
UnionFind uf(n*2);
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
a--; b--;
uf.unite(a, n+b);
uf.unite(n+a, b);
}
for(int i = 0; i < n; i++){
if(!uf.same(i, n+i)){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
Manuel1024