Submission #7491165
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x){ return Size[root(x)]; } }; int N, M; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; UnionFind uni(N + M + 1); for(int i = 1; i <= N; i++) { int K; cin >> K; while(K--) { int l; cin >> l; uni.merge(i, N + l); } } for(int i = 2; i <= N; i++) { if(!uni.issame(1, i)) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | kort0n |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1951 Byte |
Status | AC |
Exec Time | 17 ms |
Memory | 3456 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 | 13 ms | 1920 KB |
02-02.txt | AC | 14 ms | 1792 KB |
02-03.txt | AC | 12 ms | 1152 KB |
02-04.txt | AC | 17 ms | 2688 KB |
02-05.txt | AC | 15 ms | 1664 KB |
02-06.txt | AC | 17 ms | 2688 KB |
02-07.txt | AC | 16 ms | 1792 KB |
02-08.txt | AC | 13 ms | 1792 KB |
02-09.txt | AC | 16 ms | 3456 KB |
02-10.txt | AC | 13 ms | 1792 KB |
02-11.txt | AC | 13 ms | 1792 KB |
02-12.txt | AC | 14 ms | 1792 KB |
02-13.txt | AC | 13 ms | 1792 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |