結果
問題 | No.2148 ひとりUNO |
ユーザー |
|
提出日時 | 2022-12-05 05:44:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,314 bytes |
コンパイル時間 | 2,036 ms |
コンパイル使用メモリ | 183,088 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 04:19:11 |
合計ジャッジ時間 | 3,349 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 WA * 30 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,n) for(int i=0;i<int(n);i++)typedef long long ll;typedef pair<char,ll> P;typedef pair<ll,char> PP;typedef pair<P,ll> Q;typedef pair<PP,ll> QQ;ll par[200010],rk[200010],sz[200010];void init(ll n){REP(i,n+1){par[i]=i;rk[i]=0;sz[i]=1;}}ll find(ll x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}void unite(ll x,ll y){x=find(x); y=find(y);if(x==y) return;if(rk[x]<rk[y]){par[x]=y;sz[y]=sz[x]+sz[y];}else{par[y]=x;sz[x]=sz[x]+sz[y];if(rk[x]==rk[y]) rk[x]++;}}bool same(ll x,ll y){return find(x)==find(y);}ll size(ll x){return sz[find(x)];}int main(void){ll i;cin.tie(0); ios_base::sync_with_stdio(false);int T;cin >> T;REP(tc,T){ll N;cin >> N;vector<Q> q;vector<QQ> qq;REP(i,N){char c;ll x;cin >> c >> x;q.push_back(Q(P(c,x),i+1));qq.push_back(QQ(PP(x,c),i+1));}sort(q.begin(),q.end());sort(qq.begin(),qq.end());init(N);REP(i,N-1) if(q[i].first.first==q[i+1].first.first) unite(q[i].second,q[i+1].second);REP(i,N-1) if(qq[i].first.first==qq[i+1].first.first) unite(qq[i].second,qq[i+1].second);if(size(1)==N) cout << "YES" << endl;else cout << "NO" << endl;}return 0;}