Submission #6444610
Source Code Expand
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } struct UnionFind { vector<int> rank, parent, size; // +1 for 1-indexed nodes UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) { iota(parent.begin(), parent.end(), 0); // parent is itself } int root(int x) { if (x != parent[x]) { parent[x] = root(parent[x]); } return parent[x]; } bool isSame(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { return link(root(x), root(y)); } bool link(int x, int y) { if (x == y) return false; if (rank[x] > rank[y]) { parent[y] = x; size[x] += size[y]; } else { parent[x] = y; size[y] += size[x]; if (rank[x] == rank[y]) { rank[y]++; } } return true; } int getSize(int x) { return size[root(x)]; } }; int main() { int n, m; cin >> n >> m; vi k(n); vvi l(n); for (int i = 0; i < n; ++i) { cin >> k[i]; l[i].resize(k[i]); for (int j = 0; j < k[i]; ++j) { cin >> l[i][j]; } } UnionFind uf(n + m); for (int i = 0; i < n; ++i) { for (auto &lang : l[i]) { uf.unite(i, n + lang - 1); } } bool ok = true; for (int i = 0; i < n; ++i) { if (!uf.isSame(i, 0)) { ok = false; break; } } if (ok) cout << "YES" << "\n"; else cout << "NO" << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | kibuna |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 2095 Byte |
Status | AC |
Exec Time | 57 ms |
Memory | 8448 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 | 2 ms | 384 KB |
01-04.txt | AC | 2 ms | 256 KB |
01-05.txt | AC | 2 ms | 256 KB |
01-06.txt | AC | 2 ms | 256 KB |
01-07.txt | AC | 1 ms | 256 KB |
01-08.txt | AC | 2 ms | 256 KB |
01-09.txt | AC | 2 ms | 256 KB |
01-10.txt | AC | 2 ms | 384 KB |
02-01.txt | AC | 32 ms | 2048 KB |
02-02.txt | AC | 48 ms | 7040 KB |
02-03.txt | AC | 33 ms | 1792 KB |
02-04.txt | AC | 49 ms | 5376 KB |
02-05.txt | AC | 48 ms | 6016 KB |
02-06.txt | AC | 47 ms | 5376 KB |
02-07.txt | AC | 49 ms | 6656 KB |
02-08.txt | AC | 41 ms | 7296 KB |
02-09.txt | AC | 57 ms | 8448 KB |
02-10.txt | AC | 43 ms | 4480 KB |
02-11.txt | AC | 42 ms | 4480 KB |
02-12.txt | AC | 42 ms | 4480 KB |
02-13.txt | AC | 41 ms | 4480 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |