Submission #992194
Source Code Expand
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <cstring> #include <string> #include <numeric> #include <limits> #include <set> #include <map> using namespace std; struct union_find { std::vector<int> parent; int __size; union_find(int size_) : parent(size_, -1), __size(size_) {} void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { if (parent[y] < parent[x]) swap(x, y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool is_same(int x, int y) { return find(x) == find(y); } int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } int size() { return __size; } }; int n, m; vector<int> lang[100010]; int main() { while (cin >> n >> m) { for (int i = 0; i < 100010; i++) { lang[i].clear(); } union_find uf(n); for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int l; cin >> l; --l; lang[l].push_back(i); } } for (int i = 0; i < m; i++) { for (int j = 0; j < (int)lang[i].size() - 1; j++) { int a = lang[i][j]; int b = lang[i][j + 1]; uf.unite(a, b); } } cout << (uf.size() == 1 ? "YES" : "NO") << endl; } }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | tubo28 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1584 Byte |
Status | AC |
Exec Time | 51 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 | 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 | 43 ms | 4608 KB |
02-02.txt | AC | 43 ms | 3584 KB |
02-03.txt | AC | 43 ms | 3968 KB |
02-04.txt | AC | 51 ms | 4224 KB |
02-05.txt | AC | 47 ms | 3712 KB |
02-06.txt | AC | 51 ms | 4224 KB |
02-07.txt | AC | 50 ms | 3712 KB |
02-08.txt | AC | 37 ms | 3556 KB |
02-09.txt | AC | 50 ms | 3580 KB |
02-10.txt | AC | 44 ms | 4608 KB |
02-11.txt | AC | 44 ms | 4608 KB |
02-12.txt | AC | 43 ms | 4480 KB |
02-13.txt | AC | 43 ms | 4480 KB |
sample-01.txt | AC | 5 ms | 2560 KB |
sample-02.txt | AC | 5 ms | 2560 KB |