Submission #7937683
Source Code Expand
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>
using namespace std;
using P = pair<int, int>;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define fillInt(xs, x) \
for (int i = 0; i < (x); i++) \
scanf("%d", &xs[i]);
#define fillLong(xs, x) \
for (int i = 0; i < (x); i++) \
scanf("%ld", &xs[i]);
#define fillString(xs, x) \
for (int i = 0; i < (x); i++) \
cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define rep(i,n) for(auto i=0; i<(n); i++)
const int mod = 1000000007;
struct UnionFind {
vector<ll> par;
UnionFind(ll N) : par(N) {
for(int i = 0; i < N; i++) par[i] = i;
}
ll root(ll x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
par[rx] = ry;
}
bool same(ll x, ll y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
set<int> all;
UnionFind uf(m);
int f;
rep(i, n) {
int k;
cin >> k;
int fst;
cin >> fst;
all.insert(fst);
f = fst;
rep(i, k-1) {
int snd;
cin >> snd;
all.insert(snd);
uf.unite(fst, snd);
}
}
bool res = true;
for(int x: all) {
res = res && uf.same(f, x);
}
cout << (res ? "YES" : "NO") << endl;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
pony_murayama |
Language |
C++14 (Clang 3.8.0) |
Score |
400 |
Code Size |
2164 Byte |
Status |
AC |
Exec Time |
136 ms |
Memory |
4608 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 |
2 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 |
127 ms |
3968 KB |
02-02.txt |
AC |
109 ms |
384 KB |
02-03.txt |
AC |
110 ms |
2688 KB |
02-04.txt |
AC |
127 ms |
3072 KB |
02-05.txt |
AC |
117 ms |
768 KB |
02-06.txt |
AC |
136 ms |
3072 KB |
02-07.txt |
AC |
122 ms |
768 KB |
02-08.txt |
AC |
87 ms |
256 KB |
02-09.txt |
AC |
118 ms |
1024 KB |
02-10.txt |
AC |
109 ms |
4608 KB |
02-11.txt |
AC |
110 ms |
4608 KB |
02-12.txt |
AC |
115 ms |
2944 KB |
02-13.txt |
AC |
113 ms |
2944 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |