Submission #992710


Source Code Expand

// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

struct UnionFind
{
	vi root;

	UnionFind ( int N ){
		root.resize(N);
		rep(i, N) root[i] = i;
	}

	int check_root ( int x )
	{
		if( root[x] == x ) return x;
		return root[x] = check_root(root[x]);
	}
	
	void unite ( int x, int y )
	{
		int root_x = check_root(x), root_y = check_root(y);

		if( root_x == root_y ) return;
		root[root_y] = root_x;
	}
	
	int check ( int x, int y  )
	{
		int root_x = check_root(x), root_y = check_root(y);

		return root_x == root_y;
	}
};

int N, M;
vi lang[100000];
int main()
{
	cin >> N >> M;
	rep(i, N){
		int k;
		cin >> k;
		rep(j, k){
			int l;
			cin >> l;
			--l;

			lang[l].pb(i);
		}
	}

	UnionFind uf(N);
	rep(i, M){
		reep(j, 1, lang[i].size()) uf.unite(lang[i][0], lang[i][j]);
	}

	int ans = 0;
	rep(i, uf.root.size()) if( uf.root[i] == i ) ++ans;
	cout << (ans == 1 ? "YES" : "NO") << endl;
}

Submission Info

Submission Time
Task C - Interpretation
User gyuuto
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2744 Byte
Status AC
Exec Time 53 ms
Memory 4608 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 5 ms 2560 KB
01-02.txt AC 5 ms 2560 KB
01-03.txt AC 5 ms 2560 KB
01-04.txt AC 5 ms 2560 KB
01-05.txt AC 5 ms 2560 KB
01-06.txt AC 5 ms 2560 KB
01-07.txt AC 5 ms 2560 KB
01-08.txt AC 5 ms 2560 KB
01-09.txt AC 5 ms 2560 KB
01-10.txt AC 5 ms 2560 KB
02-01.txt AC 44 ms 4608 KB
02-02.txt AC 44 ms 3584 KB
02-03.txt AC 43 ms 3968 KB
02-04.txt AC 52 ms 4224 KB
02-05.txt AC 48 ms 3712 KB
02-06.txt AC 53 ms 4224 KB
02-07.txt AC 50 ms 3712 KB
02-08.txt AC 36 ms 3556 KB
02-09.txt AC 50 ms 3448 KB
02-10.txt AC 45 ms 4604 KB
02-11.txt AC 45 ms 4476 KB
02-12.txt AC 45 ms 4480 KB
02-13.txt AC 44 ms 4480 KB
sample-01.txt AC 5 ms 2560 KB
sample-02.txt AC 5 ms 2560 KB