Submission #991906
Source Code Expand
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))
using namespace std;
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
// Problem Specific Parameter:
// Description: 素集合を管理するデータ構造
// TimeComplexity: 初期化$\mathcal{O}(n)$ 更新$\mathcal{O}(\log n)$
// Verifyed: AOJ DSL_1_A
struct Union_find{
Union_find(int n){par.resize(n),iota(_all(par),0);}
int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);}
void unite(int a,int b){a=find(a),b=find(b);par[a]=b;}
bool same(int a,int b){return find(a)==find(b);}
vector<int> par;
};
vector<int> lang[100010];
int main(void){
int n,m;
cin >> n >> m;
Union_find uf(n);
rep(i,n){
int k;
cin >> k;
rep(j,k){
int in;
cin >> in,in--;
lang[in].push_back(i);
}
}
rep(i,m){
if(lang[i].empty()) continue;
int lead=lang[i][0];
for(auto &it:lang[i]) uf.unite(lead,it);
}
bool ok=true;
rep(i,n) if(uf.same(0,i)==false) ok=false;
if(ok)
puts("YES");
else
puts("NO");
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
Hec |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2077 Byte |
Status |
AC |
Exec Time |
53 ms |
Memory |
4860 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 |
2560 KB |
01-02.txt |
AC |
5 ms |
2560 KB |
01-03.txt |
AC |
5 ms |
2560 KB |
01-04.txt |
AC |
5 ms |
2560 KB |
01-05.txt |
AC |
5 ms |
2560 KB |
01-06.txt |
AC |
5 ms |
2560 KB |
01-07.txt |
AC |
5 ms |
2560 KB |
01-08.txt |
AC |
5 ms |
2560 KB |
01-09.txt |
AC |
5 ms |
2560 KB |
01-10.txt |
AC |
5 ms |
2560 KB |
02-01.txt |
AC |
44 ms |
4608 KB |
02-02.txt |
AC |
46 ms |
3584 KB |
02-03.txt |
AC |
44 ms |
3968 KB |
02-04.txt |
AC |
53 ms |
4224 KB |
02-05.txt |
AC |
53 ms |
3712 KB |
02-06.txt |
AC |
53 ms |
4224 KB |
02-07.txt |
AC |
51 ms |
3712 KB |
02-08.txt |
AC |
37 ms |
3940 KB |
02-09.txt |
AC |
52 ms |
4472 KB |
02-10.txt |
AC |
46 ms |
4860 KB |
02-11.txt |
AC |
46 ms |
4860 KB |
02-12.txt |
AC |
45 ms |
4608 KB |
02-13.txt |
AC |
49 ms |
4480 KB |
sample-01.txt |
AC |
5 ms |
2560 KB |
sample-02.txt |
AC |
5 ms |
2560 KB |