Submission #993347
Source Code Expand
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);
template<class T> inline T sqr(T x) {return x*x;}
class UnionFind {
struct UFNode {
int par;
int rank;
};
vector<UFNode> nodes;
public:
UnionFind(int n): nodes(n) {
for (int i = 0; i < n; i++) {
nodes[i].par = i;
nodes[i].rank = 0;
}
};
int root(int x) {
return nodes[x].par == x ? x : nodes[x].par = root(nodes[x].par);
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return;
if (nodes[x].rank < nodes[y].rank) {
nodes[x].par = y;
} else {
nodes[y].par = x;
if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
}
}
//~UnionFind() {cout << nodes.size() << endl;}
};
int ary[100001];
int r[100001];
int main() {
int n, m;
cin >> n >> m;
UnionFind u(m+1);
int k, in;
REP(i,0,n) {
cin >> k;
REP(j,0,k) {
cin >> ary[j];
//if (j > 0) u.unite(ary[j], ary[j-1]);
}
REP(j,1,k) u.unite(ary[j], ary[j-1]);
}
//return 0;
REP(i,0,m+1) {
r[u.root(i)]++;
//cout << u.root(i) << endl;
}
bool b = false;
REP(i,0,m+1) {
if (r[i] > 1) {
if (b) {
cout << "NO" << endl;
return 0;
} else {
b = true;
}
}
}
if (b) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
unsre |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2670 Byte |
Status |
WA |
Exec Time |
48 ms |
Memory |
1408 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 |
WA |
3 ms |
256 KB |
01-02.txt |
AC |
3 ms |
256 KB |
01-03.txt |
AC |
3 ms |
256 KB |
01-04.txt |
AC |
3 ms |
256 KB |
01-05.txt |
AC |
3 ms |
256 KB |
01-06.txt |
AC |
3 ms |
256 KB |
01-07.txt |
AC |
3 ms |
256 KB |
01-08.txt |
WA |
3 ms |
256 KB |
01-09.txt |
AC |
3 ms |
256 KB |
01-10.txt |
WA |
3 ms |
256 KB |
02-01.txt |
AC |
34 ms |
1408 KB |
02-02.txt |
WA |
38 ms |
256 KB |
02-03.txt |
AC |
33 ms |
896 KB |
02-04.txt |
AC |
42 ms |
1408 KB |
02-05.txt |
AC |
39 ms |
384 KB |
02-06.txt |
WA |
42 ms |
1408 KB |
02-07.txt |
AC |
40 ms |
384 KB |
02-08.txt |
AC |
32 ms |
256 KB |
02-09.txt |
WA |
48 ms |
1408 KB |
02-10.txt |
AC |
38 ms |
768 KB |
02-11.txt |
WA |
38 ms |
896 KB |
02-12.txt |
AC |
37 ms |
896 KB |
02-13.txt |
WA |
37 ms |
896 KB |
sample-01.txt |
AC |
3 ms |
256 KB |
sample-02.txt |
AC |
3 ms |
256 KB |