Submission #3907654
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;
template<typename T>
void printv(vector<T> const& s) {
REP(i, SZ(s)) {
cout << s[i] << " ";
}
cout << endl;
}
class UF {
vector<int> par; // 親
vector<int> rank; // 深さ
public:
void init(int n) { // n個で初期化
for(int i=0;i<n;i++) {
par.push_back(i);
rank.push_back(0);
}
}
UF(int n) {
for(int i=0;i<n;i++) {
par.push_back(i);
rank.push_back(0);
}
}
int find(int x) { // 木の中のxの親を返す
if (par[x] == x) return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) { // xとyを統合する
x = find(x);
y = find(y);
if (x == y) return;
if(rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y]) rank[x]++;
}
}
bool same(int x, int y) { // xとyが等しいかどうか判定する
return find(x) == find(y);
}
};
int main () {
cin.tie(0);
cout << setprecision(10);
int n, m; cin >> n >> m;
UF uf(n);
vvi a(m);
REP(i, n) {
int k; cin >> k;
REP(j, k) {
int l; cin >> l;
l--;
a[l].pb(i);
}
}
REP(i, m) {
FOR(j, 1, SZ(a[i])) {
uf.unite(a[i][j-1], a[i][j]);
}
}
REP(i, n-1) {
if(!uf.same(i, i+1)) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
kanra824 |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2153 Byte |
Status |
AC |
Exec Time |
48 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 |
1 ms |
256 KB |
01-03.txt |
AC |
2 ms |
256 KB |
01-04.txt |
AC |
1 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 |
39 ms |
4608 KB |
02-02.txt |
AC |
38 ms |
1652 KB |
02-03.txt |
AC |
39 ms |
2944 KB |
02-04.txt |
AC |
47 ms |
4348 KB |
02-05.txt |
AC |
44 ms |
1908 KB |
02-06.txt |
AC |
48 ms |
4476 KB |
02-07.txt |
AC |
45 ms |
2036 KB |
02-08.txt |
AC |
31 ms |
1652 KB |
02-09.txt |
AC |
45 ms |
4084 KB |
02-10.txt |
AC |
39 ms |
3708 KB |
02-11.txt |
AC |
39 ms |
3708 KB |
02-12.txt |
AC |
39 ms |
3580 KB |
02-13.txt |
AC |
39 ms |
3452 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |