Submission #992445


Source Code Expand

#include<bits/stdc++.h>

using namespace std;


template<typename T>
class UF
{
public:
	UF() {
		size = 0;
	}

	//値を挿入する
	void push( T a ) {
		M[a] = size;
		V.push_back( size );
		rank.push_back( 0 );
		C.push_back( 1 );
		size++;
	}

	//同じグループにする
	void unite( T a, T b ) {
		long long int x = find( M[a] );
		long long int y = find( M[b] );
		if( x == y )return;
		if( rank[x] < rank[y] ) {
			V[x] = y;
			C[y] += C[x];
		} else {
			V[y] = x;
			C[x] += C[y];
			if( rank[x] == rank[y] )rank[x]++;
		}
	}

	void merge( T a, T b ) {
		unite( a, b );
	}

	//同じグループにいるかどうか判定する
	bool same( T a, T b ) {
		return find( M[a] ) == find( M[b] );
	}

	//今何グループあるか数を返す
	long long int group() {
		set<long long int >S;
		for( long long int i = 0; i < V.size(); i++ ) {
			S.insert( find( V[i] ) );
		}
		return S.size();
	}

	//グループに属している数を返す
	long long int count( T a ) {
		return C[find( M[a] )];
	}

private:
	vector<long long int>
		C, V, rank;
	map < T, long long int>M;
	long long int size;

	//祖先までたどる
	long long int find( long long int x ) {
		if( V[x] == x )return x;
		else return V[x] = find( V[x] );
	}
};



int main() {
	UF<long long int>uf;
	long long int N, M;
	cin >> N >> M;
	for( size_t i = 0; i < N + M; i++ ) {
		uf.push( i );
	}
	for( size_t i = 0; i < N; i++ ) {
		long long int K;
		cin >> K;
		for( size_t j = 0; j < K; j++ ) {
			long long int L;
			cin >> L;
			L--;
			uf.merge( i, L + N );
		}
	}
	bool f = true;
	for( size_t i = 1; i < N; i++ ) {
		f = f&&uf.same( 0, i );
	}
	cout << (f ? "YES" : "NO") << endl;
}

Submission Info

Submission Time
Task C - Interpretation
User goryudyuma
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1767 Byte
Status AC
Exec Time 167 ms
Memory 17492 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 25
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 3 ms 256 KB
01-02.txt AC 3 ms 384 KB
01-03.txt AC 4 ms 384 KB
01-04.txt AC 3 ms 384 KB
01-05.txt AC 3 ms 384 KB
01-06.txt AC 3 ms 384 KB
01-07.txt AC 3 ms 384 KB
01-08.txt AC 3 ms 384 KB
01-09.txt AC 3 ms 384 KB
01-10.txt AC 3 ms 384 KB
02-01.txt AC 109 ms 9312 KB
02-02.txt AC 105 ms 8672 KB
02-03.txt AC 86 ms 5356 KB
02-04.txt AC 155 ms 13652 KB
02-05.txt AC 118 ms 8032 KB
02-06.txt AC 148 ms 13652 KB
02-07.txt AC 129 ms 8800 KB
02-08.txt AC 102 ms 8800 KB
02-09.txt AC 167 ms 17492 KB
02-10.txt AC 98 ms 8800 KB
02-11.txt AC 98 ms 8800 KB
02-12.txt AC 108 ms 8800 KB
02-13.txt AC 105 ms 8800 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB