Submission #992798
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
typedef long long ll;
int const inf = 1<<29;
namespace tree {
struct union_find {
vector<int> par, rank, size;
int compnum;
union_find(int N) {
compnum = N;
par.resize(N), rank.resize(N), size.resize(N);
for(int i=0; i<N; i++) {
par[i] = i;
rank[i] = 0;
size[i] = 1;
}
}
int root(int x) {
return par[x] == x ? x : par[x] = root(par[x]);
}
void unite(int x, int y) {
x = root(x), y = root(y);
if(x == y) return;
if(rank[x] < rank[y]) {
par[x] = y, size[y] += size[x];
} else {
par[y] = x, size[x] += size[y];
if(rank[x] == rank[y]) rank[x]++;
}
compnum--;
}
int operator[](int x) { return root(x); }
void operator()(int x, int y) { return unite(x, y); }
bool same(int x, int y) { return root(x) == root(y); }
int size_of(int x) { return size[root(x)]; }
int num_of_comps() { return compnum; }
};
}
int main() {
int N, M; cin >> N >> M;
vector<vector<int>> user(M);
tree::union_find uf(N);
rep(i, N) {
int K; cin >> K;
rep(j, K) {
int l; cin >> l; l --;
user[l].push_back(i);
}
}
for(auto& e: user) {
if(e.size()) {
int fst = e[0];
REP(i, 1, (int)e.size()) {
uf(fst, e[i]);
}
}
}
// cout << uf.num_of_comps() << endl;
cout << (uf.num_of_comps() == 1 ? "YES" : "NO") << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
motxx |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1953 Byte |
Status |
AC |
Exec Time |
53 ms |
Memory |
4608 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 |
2 ms |
256 KB |
01-02.txt |
AC |
3 ms |
256 KB |
01-03.txt |
AC |
3 ms |
256 KB |
01-04.txt |
AC |
3 ms |
256 KB |
01-05.txt |
AC |
3 ms |
256 KB |
01-06.txt |
AC |
3 ms |
256 KB |
01-07.txt |
AC |
3 ms |
256 KB |
01-08.txt |
AC |
3 ms |
256 KB |
01-09.txt |
AC |
3 ms |
256 KB |
01-10.txt |
AC |
3 ms |
256 KB |
02-01.txt |
AC |
43 ms |
4608 KB |
02-02.txt |
AC |
43 ms |
1920 KB |
02-03.txt |
AC |
42 ms |
2944 KB |
02-04.txt |
AC |
53 ms |
4608 KB |
02-05.txt |
AC |
48 ms |
2176 KB |
02-06.txt |
AC |
53 ms |
4608 KB |
02-07.txt |
AC |
49 ms |
2304 KB |
02-08.txt |
AC |
35 ms |
1920 KB |
02-09.txt |
AC |
52 ms |
4348 KB |
02-10.txt |
AC |
44 ms |
3840 KB |
02-11.txt |
AC |
44 ms |
3840 KB |
02-12.txt |
AC |
43 ms |
3712 KB |
02-13.txt |
AC |
44 ms |
3712 KB |
sample-01.txt |
AC |
2 ms |
256 KB |
sample-02.txt |
AC |
3 ms |
256 KB |