Submission #1456090
Source Code Expand
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #include "dump.hpp" #else #define dump(...) #endif //#define int long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9) + 7; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } struct UnionFind { vector<int> parent; int size; UnionFind(int n) :parent(n, -1), size(n) {} bool unite(int x, int y) { x = root(x); y = root(y); if (x == y)return false; if (sizeOf(x) < sizeOf(y))swap(x, y); parent[x] += parent[y]; parent[y] = x; size--; return true; } bool same(int x, int y) { return root(x) == root(y); } int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); } int sizeOf(int x) { return -parent[root(x)]; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; UnionFind uf(N + M); rep(i, 0, N) { int k; cin >> k; rep(j, 0, k) { int l; cin >> l; l--; uf.unite(i, N + l); } } rep(i, 0, N - 1) { if (!uf.same(i, i + 1)) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | minaminao |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1447 Byte |
Status | AC |
Exec Time | 16 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 | 11 ms | 640 KB |
02-02.txt | AC | 14 ms | 640 KB |
02-03.txt | AC | 11 ms | 640 KB |
02-04.txt | AC | 15 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 | 16 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 |