Submission #8069298
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, a, b) for (int i = a; i <= (b); ++i) #define repr(i, a, b) for (int i = a; i >= (b); --i) #define bit(n) (1LL << (n)) #define sz(x) ((int)(x).size()) typedef long long ll; const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1000000007; template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } /* O(log n) */ struct UnionFind { vector<int> parent; // parent[root] is the negative of the size. UnionFind(int n) : parent(n, -1){}; bool unite(int u, int v) { u = root(u); v = root(v); if (u == v) return false; if (parent[u] > parent[v]) swap(u, v); parent[u] += parent[v]; parent[v] = u; return true; } bool issame(int u, int v) { return root(u) == root(v); } int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); } int size(int u) { return -parent[root(u)]; } }; int main() { int N, M; cin >> N >> M; vector<int> K(N); vector<vector<int>> L(N); vector<bool> used(M, false); rep(i, N) { cin >> K[i]; rep(j, K[i]) { int temp; cin >> temp; temp--; L[i].pb(temp); used[temp] = true; } } UnionFind U(M); rep(i, N) { rep(j, K[i] - 1) { U.unite(L[i][j], L[i][j + 1]); } } int r = -1; rep(i, M) { if (!used[i]) continue; if (r == -1) r = U.root(i); else { if (r != U.root(i)) { cout << "NO" << endl; return 0; } } } cout << "YES" << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | theta |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 2003 Byte |
Status | AC |
Exec Time | 52 ms |
Memory | 6528 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 | 256 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 | 2 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 | 256 KB |
02-01.txt | AC | 34 ms | 1408 KB |
02-02.txt | AC | 44 ms | 5888 KB |
02-03.txt | AC | 35 ms | 1408 KB |
02-04.txt | AC | 46 ms | 3968 KB |
02-05.txt | AC | 48 ms | 4992 KB |
02-06.txt | AC | 46 ms | 3968 KB |
02-07.txt | AC | 47 ms | 5504 KB |
02-08.txt | AC | 39 ms | 6144 KB |
02-09.txt | AC | 52 ms | 6528 KB |
02-10.txt | AC | 41 ms | 3584 KB |
02-11.txt | AC | 41 ms | 3580 KB |
02-12.txt | AC | 39 ms | 3584 KB |
02-13.txt | AC | 39 ms | 3584 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |