結果
| 問題 | No.2148 ひとりUNO |
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2022-12-12 00:32:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,418 bytes |
| 記録 | |
| コンパイル時間 | 1,836 ms |
| コンパイル使用メモリ | 206,052 KB |
| 最終ジャッジ日時 | 2025-02-09 09:51:26 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par;
vector<int> size;
UnionFind(int n) {
par.resize(n);
size.resize(n,1);
for(int i = 0; i < n; i++) {
par[i] = i;
}
}
int find(int x) {
if(par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
bool same(int x, int y) {
return find(x) == find(y);
}
int consize(int x) {
return size[find(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);
}
par[x] = y;
size[y] += size[x];
return true;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--) {
int N;
cin >> N;
vector<char>C(N);
vector<int>D(N);
UnionFind uf(2*N+3);
for(int i = 0; i < N; i++) {
cin >> C[i] >> D[i];
D[i]--;
for(int j = 0; j < 3; j++) {
if("RGB"[j] == C[i]) uf.unite(N+j,i);
}
uf.unite(N+3+D[i],i);
}
set<int>st;
for(int i = 0; i < N; i++) {
st.insert(uf.find(i));
}
cout << ((st.size() == 1)?"YES":"NO") << "\n";
}
}
ぷら