Submission #992297
Source Code Expand
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
const int MOD = 1000000007;
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
class UnionFind {
vector<int> pir;
public:
UnionFind(int size) : pir(size, -1) { }
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (pir[y] < pir[x]) swap(x, y);
pir[x] += pir[y];
pir[y] = x;
}
return x != y;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
if (pir[x] < 0) {
return x;
} else {
return pir[x] = root(pir[x]);
}
}
int size(int x) {
return -pir[root(x)];
}
};
signed main(void) {
ios::sync_with_stdio(false);
cout.setf(ios::fixed, ios::floatfield);
cout.precision(10);
cin.tie(0);
int n,m;
cin >> n >> m;
VI k(n);
VVI l(n,VI());
REP(i,n){
cin >> k[i];
REP(j,k[i]){
int t;
cin >> t;
l[i].push_back(t);
}
}
UnionFind uf(m);
REP(i,n){
FOR(j,1,k[i]){
uf.unite(l[i][0],l[i][j]);
}
}
FOR(i,1,n){
if(!uf.same(l[0][0],l[i][0])){
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
NSTomoS |
Language |
C++11 (GCC 4.8.1) |
Score |
400 |
Code Size |
2398 Byte |
Status |
AC |
Exec Time |
27 ms |
Memory |
7296 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 |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
8 ms |
768 KB |
01-02.txt |
AC |
2 ms |
256 KB |
01-03.txt |
AC |
2 ms |
384 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 |
384 KB |
02-01.txt |
AC |
16 ms |
2432 KB |
02-02.txt |
AC |
25 ms |
6272 KB |
02-03.txt |
AC |
18 ms |
2176 KB |
02-04.txt |
AC |
24 ms |
4736 KB |
02-05.txt |
AC |
24 ms |
5376 KB |
02-06.txt |
AC |
24 ms |
4736 KB |
02-07.txt |
AC |
26 ms |
6016 KB |
02-08.txt |
AC |
23 ms |
6528 KB |
02-09.txt |
AC |
27 ms |
7296 KB |
02-10.txt |
AC |
20 ms |
4220 KB |
02-11.txt |
AC |
19 ms |
4216 KB |
02-12.txt |
AC |
19 ms |
4096 KB |
02-13.txt |
AC |
19 ms |
4224 KB |
sample-01.txt |
AC |
2 ms |
256 KB |
sample-02.txt |
AC |
2 ms |
256 KB |