Submission #7424724
Source Code Expand
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{template<class U>static auto c(U v)->decltype(v.begin(),v.end(),std::true_type());static std::false_type c(...);public:const static bool value=decltype(c(std::declval<T>()))::value;};
template<class T,typename enable_if<iterable<T>::value, nullptr_t>::type=nullptr>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}
class UnionFind{
private:
vi data;
public:
UnionFind(int size):data(size,-1){}
bool unite(int x,int y){
x=root(x);y=root(y);
if(x!=y){
if(data[y]<data[x])swap(x,y);
data[x]+=data[y];data[y]=x;
}
return x!=y;
}
bool find(int x,int y){
return root(x)==root(y);
}
int root(int x){
return data[x]<0?x:data[x]=root(data[x]);
}
int size(int x){
return -data[root(x)];
}
void dbg(){dprint(data);}
};
int main(){
cin.tie(0);ios::sync_with_stdio(0);
int n,m;
cin>>n>>m;
UnionFind uf(n);
vi s(m, -1);
REP(i,n){
int k;
cin>>k;
REP(j,k){
int l;
cin>>l;
if(s[l-1]==-1){
dprint(i,"I am first speaker", l-1);
s[l-1]=i;
}else{
dprint(i,"He is first speaker", l-1, s[l-1]);
uf.unite(s[l-1], i);
}
}
}
uf.dbg();
dprint(s);
YES(uf.size(0)==n);
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
ibuki2003 |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
3426 Byte |
Status |
AC |
Exec Time |
15 ms |
Memory |
1024 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, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
1 ms |
256 KB |
01-02.txt |
AC |
1 ms |
256 KB |
01-03.txt |
AC |
1 ms |
256 KB |
01-04.txt |
AC |
1 ms |
256 KB |
01-05.txt |
AC |
1 ms |
256 KB |
01-06.txt |
AC |
1 ms |
256 KB |
01-07.txt |
AC |
1 ms |
256 KB |
01-08.txt |
AC |
1 ms |
256 KB |
01-09.txt |
AC |
1 ms |
256 KB |
01-10.txt |
AC |
1 ms |
256 KB |
02-01.txt |
AC |
10 ms |
640 KB |
02-02.txt |
AC |
14 ms |
640 KB |
02-03.txt |
AC |
10 ms |
512 KB |
02-04.txt |
AC |
14 ms |
896 KB |
02-05.txt |
AC |
14 ms |
640 KB |
02-06.txt |
AC |
14 ms |
896 KB |
02-07.txt |
AC |
15 ms |
640 KB |
02-08.txt |
AC |
13 ms |
640 KB |
02-09.txt |
AC |
15 ms |
1024 KB |
02-10.txt |
AC |
12 ms |
640 KB |
02-11.txt |
AC |
12 ms |
640 KB |
02-12.txt |
AC |
12 ms |
640 KB |
02-13.txt |
AC |
12 ms |
640 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |