Submission #2127185


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2016-final_c / Link: https://cf16-final.contest.atcoder.jp/tasks/codefestival_2016_final_c?lang=en  ----- */
/* ------問題------

ある星には M 種類の言語があり、1-M の番号が付けられています。

この星のある年のCODE FESTIVALには星中から N 人の参加者が集まりました。

i(1≦i≦N) 人目の参加者は Ki 種類の言語 Li,1,Li,2,…,Li,Ki を話すことが出来ます。

ある 2 人は以下のいずれかの条件を満たすときに限り、コミュニケーションを取ることが出来ます。

2 人ともが話すことの出来る言語が存在する。
ある人 X が存在して、 2 人ともが X とコミュニケーションを取ることが出来る。
このとき、N 人すべての参加者が他のすべての参加者とコミュニケーションを取ることが出来るかどうかを判定してください。

-----問題ここまで----- */
/* -----解説等-----

何でもかんでも繋がっていれば良い

----解説ここまで---- */

LL N,M;

LL ans = 0LL;

void dfs(int v, int p, VVI &G, VI& visit) {
	visit[v] = 1;
	FOR(i, 0, SZ(G[v])) {
		int nx = G[v][i];
		if (nx != p && !visit[nx])dfs(nx, v, G, visit);
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N>>M;
	VVI G(N + M);
	FOR(i, 0, N) {
		int k;
		cin >> k;
		FOR(j, 0, k) {
			int lg;
			cin >> lg;
			lg--;
			lg += N;
			G[i].push_back(lg);
			G[lg].push_back(i);
		}
	}

	VI visit(N+M);
	dfs(0,-1,G,visit);
	ans = 1;
	FOR(i, 0, N) {
		if (!visit[i])ans = 0;
	}
	cout << (ans?"YES":"NO") << "\n";

	return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User Yang33
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2701 Byte
Status AC
Exec Time 33 ms
Memory 9208 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 27
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 384 KB
01-03.txt AC 1 ms 384 KB
01-04.txt AC 1 ms 384 KB
01-05.txt AC 1 ms 384 KB
01-06.txt AC 1 ms 384 KB
01-07.txt AC 1 ms 384 KB
01-08.txt AC 1 ms 384 KB
01-09.txt AC 1 ms 384 KB
01-10.txt AC 1 ms 384 KB
02-01.txt AC 23 ms 6272 KB
02-02.txt AC 24 ms 6656 KB
02-03.txt AC 25 ms 5120 KB
02-04.txt AC 33 ms 7680 KB
02-05.txt AC 29 ms 6656 KB
02-06.txt AC 31 ms 7680 KB
02-07.txt AC 28 ms 6528 KB
02-08.txt AC 19 ms 6520 KB
02-09.txt AC 23 ms 9208 KB
02-10.txt AC 19 ms 6520 KB
02-11.txt AC 19 ms 6520 KB
02-12.txt AC 21 ms 6400 KB
02-13.txt AC 21 ms 6400 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB