Submission #7885855
Source Code Expand
#include <bits/stdc++.h> using namespace std; #include<iostream> #include<vector> using namespace std; typedef long long ll; class DisjointSet{ public: vector<int> rank, p, num; DisjointSet(){} DisjointSet(int size){ rank.resize(size, 0); p.resize(size, 0); num.resize(size, 0); for(int i = 0; i < size; i++) makeSet(i); } void makeSet(int x){ p[x] = x; rank[x] = 0; num[x] = 1; }//グループを作る bool same(int x, int y){ return findSet(x) == findSet(y); //x,yが同じグループに属しているか判定 } void unite(int x, int y){ link(findSet(x), findSet(y)); }//xとyの属するsetを結合する void link(int x, int y){ if(rank[x] > rank[y]){ p[y] = x; num[x] += num[y]; num[y] = 0; }else{ p[x] = y; if( rank[x] == rank[y]){ rank[y]++; } num[y] += num[x]; num[x] = 0; } }//rankが大きい方の下にrankが小さいものをくっつける int findSet(int x){ if(x != p[x]){ p[x] = findSet(p[x]); } return p[x]; }//再帰的にxの親を見つけている int size(int x){ return num[findSet(x)]; }// xの属する集合の大きさを返す }; //DisjointSet ds = DisjointSet(V);//初期化の方法 int main(){ int N, M; cin >> N >> M; DisjointSet ds = DisjointSet(N + M); for(int i = 0; i < N; i++){ int k; cin >> k; for(int j = 0; j < k; j++){ int l; cin >> l; l--; ds.unite(i + M, l); } } bool flag = 1; for(int i = 1; i < N; i++){ if(!ds.same(M, M + i)){ flag = 0; break; } } if(flag) puts("YES"); else puts("NO"); }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | raoZ |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 2160 Byte |
Status | AC |
Exec Time | 47 ms |
Memory | 2560 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 | 1 ms | 256 KB |
01-06.txt | AC | 1 ms | 256 KB |
01-07.txt | AC | 1 ms | 256 KB |
01-08.txt | AC | 1 ms | 256 KB |
01-09.txt | AC | 1 ms | 256 KB |
01-10.txt | AC | 2 ms | 256 KB |
02-01.txt | AC | 33 ms | 1536 KB |
02-02.txt | AC | 39 ms | 1408 KB |
02-03.txt | AC | 34 ms | 896 KB |
02-04.txt | AC | 44 ms | 2048 KB |
02-05.txt | AC | 41 ms | 1280 KB |
02-06.txt | AC | 43 ms | 2048 KB |
02-07.txt | AC | 43 ms | 1408 KB |
02-08.txt | AC | 33 ms | 1408 KB |
02-09.txt | AC | 47 ms | 2560 KB |
02-10.txt | AC | 38 ms | 1408 KB |
02-11.txt | AC | 38 ms | 1408 KB |
02-12.txt | AC | 37 ms | 1408 KB |
02-13.txt | AC | 37 ms | 1408 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |