Submission #992152
Source Code Expand
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
stringstream ss;
ss << from; ss >> to;
}
class UnionFind {
private:
Vec< int > data;
int num_of_g;
public:
UnionFind(int n) : data(n, -1), num_of_g(n) {}
bool unionSet(int x, int y) {
x = root(x); y = root(y);
if (x == y) return 0;
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
--num_of_g;
return 1;
}
bool sameSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
int getNumOfG() { return num_of_g; }
};
int N, M;
int main() {
cin >> N >> M;
UnionFind uf(M);
set< int > all_L;
for_(i,0,N) {
int K; cin >> K;
int prev; cin >> prev; --prev;
all_L.insert(prev);
--K;
for_(j,0,K) {
int L; cin >> L; --L;
all_L.insert(L);
uf.unionSet(prev, L);
prev = L;
--K;
}
}
set< int > roots;
for (int x : all_L) roots.insert(uf.root(x));
cout << (roots.size() == 1 ? "YES": "NO") << endl;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
tsukasa_diary |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3098 Byte |
Status |
WA |
Exec Time |
190 ms |
Memory |
6272 KB |
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
0 / 200 |
0 / 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 |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
3 ms |
256 KB |
01-02.txt |
WA |
3 ms |
256 KB |
01-03.txt |
AC |
3 ms |
256 KB |
01-04.txt |
AC |
3 ms |
256 KB |
01-05.txt |
RE |
112 ms |
256 KB |
01-06.txt |
RE |
112 ms |
256 KB |
01-07.txt |
RE |
111 ms |
256 KB |
01-08.txt |
RE |
113 ms |
256 KB |
01-09.txt |
RE |
112 ms |
256 KB |
01-10.txt |
AC |
3 ms |
256 KB |
02-01.txt |
RE |
175 ms |
4864 KB |
02-02.txt |
RE |
156 ms |
896 KB |
02-03.txt |
AC |
60 ms |
2688 KB |
02-04.txt |
RE |
190 ms |
6272 KB |
02-05.txt |
RE |
181 ms |
4480 KB |
02-06.txt |
RE |
186 ms |
5504 KB |
02-07.txt |
RE |
185 ms |
4736 KB |
02-08.txt |
AC |
33 ms |
256 KB |
02-09.txt |
AC |
47 ms |
640 KB |
02-10.txt |
WA |
51 ms |
2816 KB |
02-11.txt |
AC |
52 ms |
2816 KB |
02-12.txt |
WA |
62 ms |
2816 KB |
02-13.txt |
RE |
169 ms |
3840 KB |
sample-01.txt |
AC |
3 ms |
256 KB |
sample-02.txt |
AC |
3 ms |
256 KB |