Submission #1678106
Source Code Expand
// 基本テンプレート
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;
// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
const int n;
int __size;
vector<int> uf;
public:
// 初期化 UnionFind uni(n) のように宣言すれば良い
UnionFind(int _n) : n(_n), __size(_n), uf(_n, -1) {}
// find (木の根を求める)
int find(int x) {return (uf[x] < 0) ? x : uf[x] = find(uf[x]);}
// x と y が同じ集合に属するかどうか
bool same(int x, int y) {return find(x) == find(y);}
// x が属する集合の要素数
int size(int x) {return -uf[find(x)];}
// 集合はいくつあるか
int size() {return __size;}
// x と y の属する集合を併合
void unite(int x, int y) {
x = find(x); y = find(y);
if(x == y) return;
__size--;
if(uf[y] < uf[x]) swap(x, y);
uf[x] += uf[y]; uf[y] = x;
}
};
signed main() {
int N, M; cin >> N >> M;
vector<int> lang[100010];
rep(i,0,N) {
int k; cin >> k;
rep(j,0,k) {
int L; cin >> L; L--;
lang[L].push_back(i);
}
}
UnionFind uf(N);
rep(i,0,M) {
rep(j,0,(int)lang[i].size() - 1) {
int p = lang[i][j], q = lang[i][j+1];
// printf("i = %lld, p = %lld, q = %lld\n", i, p, q);
uf.unite(p, q);
}
}
int sz = uf.size(0);
if(sz == N) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
tsutaj |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2579 Byte |
Status |
AC |
Exec Time |
48 ms |
Memory |
4992 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 |
2 ms |
2560 KB |
01-02.txt |
AC |
2 ms |
2560 KB |
01-03.txt |
AC |
2 ms |
2560 KB |
01-04.txt |
AC |
2 ms |
2560 KB |
01-05.txt |
AC |
2 ms |
2560 KB |
01-06.txt |
AC |
2 ms |
2560 KB |
01-07.txt |
AC |
3 ms |
2560 KB |
01-08.txt |
AC |
3 ms |
2560 KB |
01-09.txt |
AC |
2 ms |
2560 KB |
01-10.txt |
AC |
2 ms |
2560 KB |
02-01.txt |
AC |
39 ms |
4736 KB |
02-02.txt |
AC |
42 ms |
4480 KB |
02-03.txt |
AC |
40 ms |
4352 KB |
02-04.txt |
AC |
48 ms |
4736 KB |
02-05.txt |
AC |
45 ms |
4608 KB |
02-06.txt |
AC |
47 ms |
4736 KB |
02-07.txt |
AC |
47 ms |
4736 KB |
02-08.txt |
AC |
35 ms |
4296 KB |
02-09.txt |
AC |
48 ms |
4340 KB |
02-10.txt |
AC |
41 ms |
4984 KB |
02-11.txt |
AC |
43 ms |
4984 KB |
02-12.txt |
AC |
40 ms |
4992 KB |
02-13.txt |
AC |
41 ms |
4864 KB |
sample-01.txt |
AC |
2 ms |
2560 KB |
sample-02.txt |
AC |
2 ms |
2560 KB |