Submission #993139
Source Code Expand
#include <iostream> #include <vector> using namespace std; class union_find { public: union_find(int n) : par_(n, -1) {} void init(int n) { par_.assign(n, -1); } int root(int x) { return par_[x] < 0 ? x : par_[x] = root(par_[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if(x == y) { return false; } else { if(par_[x] < par_[y]) { // size(x) > size(y) par_[x] += par_[y]; par_[y] = x; } else { par_[y] += par_[x]; par_[x] = y; } return true; } } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par_[root(x)]; } private: std::vector<int> par_; }; int main() { int N, M; cin >> N >> M; union_find uf(N); vector<vector<int>> l(M+1); for(int i=0; i<N; ++i) { int K=0; cin >> K; for(int j=0; j<K; ++j) { int L; cin >> L; L--; l[L].push_back(i); } } for(int i=0; i<l.size(); ++i) { for(int j=1; j<l[i].size(); ++j) { uf.unite(l[i][j], l[i][j-1]); } } for(int i=0; i<N-1; ++i) { if(!uf.same(i, i+1)) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | Suibaka |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1523 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 | 3 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 | 45 ms | 4608 KB |
02-02.txt | AC | 42 ms | 1280 KB |
02-03.txt | AC | 42 ms | 2816 KB |
02-04.txt | AC | 53 ms | 4224 KB |
02-05.txt | AC | 47 ms | 1536 KB |
02-06.txt | AC | 53 ms | 4224 KB |
02-07.txt | AC | 48 ms | 1664 KB |
02-08.txt | AC | 34 ms | 1152 KB |
02-09.txt | AC | 52 ms | 3580 KB |
02-10.txt | AC | 45 ms | 3456 KB |
02-11.txt | AC | 44 ms | 3456 KB |
02-12.txt | AC | 44 ms | 3328 KB |
02-13.txt | AC | 43 ms | 3328 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |