Submission #993448
Source Code Expand
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
using namespace std;
const int SIZE=5*1e5;
const LL INF=1LL<<58;
const LL p=1e9+7;
class UnionFind{
vector<int> unions,talls,sents,dists,sizes;
int size;
public:
UnionFind(){}
UnionFind(int size):size(size){
init();
}
void init(){
unions=vector<int>(size);
talls=vector<int>(size);
sents=vector<int>(size);
dists=vector<int>(size);
sizes=vector<int>(size);
FOR(i,0,size){
unions[i]=i;
sents[i]=0;
sizes[i]=1;
// ns[i].PB(pr(0,1));
talls[i]=1;
}
}
int find(int x,int t=0){
if(unions[x]==x || sents[x]>t) return x;
return find(unions[x],t);
}
int minisize(int x){
if(x==unions[x]) return sizes[x];
return minisize(find(x));
}
bool isFriend(int a,int b,int t=0){
return find(a,t)==find(b,t);
}
void unite(int a,int b,int t=0){
if(isFriend(a,b,t)) return;
a=find(a,t);
b=find(b,t);
if(talls[a]<talls[b]) unite(b,a,t);
else{
sizes[a]+=sizes[b];
sents[b]=t;
talls[a]=max(talls[a],talls[b]+1);
unions[b]=a;
dists[b]=1;
// ns[a].PB(pr(t,ns[b].back().second+ns[a].back().second));
}
}
};
UnionFind uf=UnionFind(1e5+5);
int L[SIZE];
bool userable[SIZE];
bool solve(){
int N,K,M;
cin.tie(0);
cin >> N >> M;
REP(i,N){
cin >> K;
REP(i,K){
cin >> L[i];
userable[L[i]]=true;
uf.unite(L[0],L[i]);
}
}
int roots=0;
FOR(i,1,M+1){
if(userable[i]&&uf.find(i)==i) roots++;
}
return roots==1;
}
int main(){
if(solve()) cout <<"YES" << endl;
else cout << "NO" << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
reew2n |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2017 Byte |
Status |
AC |
Exec Time |
46 ms |
Memory |
2432 KB |
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
200 / 200 |
200 / 200 |
Status |
|
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
dataset1 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
dataset2 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
5 ms |
2176 KB |
01-02.txt |
AC |
5 ms |
2176 KB |
01-03.txt |
AC |
5 ms |
2176 KB |
01-04.txt |
AC |
5 ms |
2176 KB |
01-05.txt |
AC |
5 ms |
2176 KB |
01-06.txt |
AC |
5 ms |
2176 KB |
01-07.txt |
AC |
5 ms |
2176 KB |
01-08.txt |
AC |
5 ms |
2176 KB |
01-09.txt |
AC |
5 ms |
2176 KB |
01-10.txt |
AC |
5 ms |
2176 KB |
02-01.txt |
AC |
36 ms |
2304 KB |
02-02.txt |
AC |
40 ms |
2176 KB |
02-03.txt |
AC |
35 ms |
2304 KB |
02-04.txt |
AC |
44 ms |
2304 KB |
02-05.txt |
AC |
41 ms |
2176 KB |
02-06.txt |
AC |
44 ms |
2304 KB |
02-07.txt |
AC |
42 ms |
2176 KB |
02-08.txt |
AC |
32 ms |
2304 KB |
02-09.txt |
AC |
46 ms |
2176 KB |
02-10.txt |
AC |
39 ms |
2432 KB |
02-11.txt |
AC |
39 ms |
2432 KB |
02-12.txt |
AC |
39 ms |
2304 KB |
02-13.txt |
AC |
39 ms |
2304 KB |
sample-01.txt |
AC |
5 ms |
2176 KB |
sample-02.txt |
AC |
5 ms |
2176 KB |