Submission #1456100
Source Code Expand
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "math.h" #include "utility" #include "string" #include "map" #include "unordered_map" #include "iomanip" #include "random" using namespace std; const long long int MOD = 1000000007; long long int power(long long int x, long long int n, long long int M) { long long int tmp = 1; if (n > 0) { tmp = power(x, n / 2, M); if (n % 2 == 0) tmp = (tmp*tmp) % M; else tmp = (((tmp*tmp) % M)*x) % M; } return tmp; } long long int N, M, K, Q, W, H, L, R; long long int ans; class UnionFind { vector<int>parent; vector<int>rank; public: UnionFind(int num) { num++; parent.resize(num); rank.resize(num); for (int i = 0; i < num; i++) { parent[i] = i; rank[i] = 0; } } int Find(int node) { if (parent[node] == node)return node; else return parent[node] = Find(parent[node]); } void Unite(int u, int v) { u = Find(u); v = Find(v); if (u == v)return; if (rank[u] < rank[v])parent[u] = v; else { parent[v] = u; if (rank[u] == rank[v])rank[u]++; } } bool Check_Same(int u, int v) { return Find(u) == Find(v); } }; int main() { ios::sync_with_stdio(false); cin >> N >> M; UnionFind u(N + M + 1); vector<pair<int, int>>v; for (int i = 1; i <= N; i++) { cin >> K; for (int j = 0; j < K; j++) { cin >> Q; u.Unite(i, N + Q); v.push_back({ Q,i }); } } sort(v.begin(), v.end()); for (int i = 0; i < v.size() - 1; i++) { if (v[i].first == v[i + 1].first) { u.Unite(v[i].second, v[i + 1].second); } } ans = u.Find(1); for (int i = 2; i <= N; i++) { if (ans != u.Find(i)) { cout << "NO\n"; return 0; } } cout << "YES\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | olphe |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1865 Byte |
Status | AC |
Exec Time | 26 ms |
Memory | 2936 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 | 21 ms | 2296 KB |
02-02.txt | AC | 24 ms | 2168 KB |
02-03.txt | AC | 21 ms | 1912 KB |
02-04.txt | AC | 26 ms | 2680 KB |
02-05.txt | AC | 25 ms | 2168 KB |
02-06.txt | AC | 26 ms | 2680 KB |
02-07.txt | AC | 26 ms | 2168 KB |
02-08.txt | AC | 21 ms | 2168 KB |
02-09.txt | AC | 20 ms | 2936 KB |
02-10.txt | AC | 21 ms | 2168 KB |
02-11.txt | AC | 20 ms | 2168 KB |
02-12.txt | AC | 22 ms | 2168 KB |
02-13.txt | AC | 22 ms | 2168 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |