Submission #7046579
Source Code Expand
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <queue> #include <stack> #include <cstdlib> #include <map> #include <iomanip> #include <set> using namespace std; #define pie 3.141592653589793238462643383279 #define int long long #define mod 1000000007 #define INF 1145141919364364 #define all(vec) vec.begin(),vec.end() #define P pair<int,int> #define S second #define F first int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x%y); } int lcm(int x, int y) { return x / gcd(x, y)*y; } bool prime(int x) { for (int i = 2; i <= sqrt(x); i++) { if (x%i == 0)return false; } return true; } int kai(int x) { if (x == 0)return 1; return kai(x - 1)*x%mod; } int mod_pow(int x, int y, int mood) { int res = 1; while (y > 0) { if (y & 1)res = res * x%mood; x = x * x%mood; y >>= 1; } return res; } int comb(int x, int y) { return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod; } int n, m, k, l; class Union_Find { private: int par[200010], rank[200010]; public: void init(int n) { for (int i = 1; i <= n; i++) { par[i] = i; rank[i] = 0; } } int find(int x) { if (par[x] == x)return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (rank[x] < rank[y])par[x] = y; else { par[y] = x; if (rank[x] == rank[y])rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; signed main() { cin >> n >> m; Union_Find ta; ta.init(n + m); for (int i = 0; i < n; i++) { cin >> k; for (int j = 0; j < k; j++) { cin >> l; ta.unite(i + 1, n + l); } } for (int i = 1; i < n; i++) { if (!ta.same(i, i + 1)) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | tamurin |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1948 Byte |
Status | AC |
Exec Time | 46 ms |
Memory | 3328 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 | 2 ms | 2304 KB |
01-02.txt | AC | 2 ms | 2304 KB |
01-03.txt | AC | 2 ms | 256 KB |
01-04.txt | AC | 1 ms | 256 KB |
01-05.txt | AC | 2 ms | 256 KB |
01-06.txt | AC | 2 ms | 2304 KB |
01-07.txt | AC | 2 ms | 2304 KB |
01-08.txt | AC | 2 ms | 2304 KB |
01-09.txt | AC | 2 ms | 2304 KB |
01-10.txt | AC | 2 ms | 256 KB |
02-01.txt | AC | 32 ms | 1920 KB |
02-02.txt | AC | 38 ms | 1792 KB |
02-03.txt | AC | 33 ms | 2816 KB |
02-04.txt | AC | 42 ms | 2688 KB |
02-05.txt | AC | 40 ms | 2944 KB |
02-06.txt | AC | 41 ms | 3072 KB |
02-07.txt | AC | 41 ms | 2944 KB |
02-08.txt | AC | 32 ms | 3072 KB |
02-09.txt | AC | 46 ms | 3328 KB |
02-10.txt | AC | 37 ms | 3072 KB |
02-11.txt | AC | 37 ms | 2944 KB |
02-12.txt | AC | 36 ms | 2944 KB |
02-13.txt | AC | 36 ms | 2816 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 2 ms | 2304 KB |