Submission #1678236


Source Code Expand

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(void) {
	int N,M,K,temp;
	cin >> N >> M;
	vector< vector<int> > ps(N);
	vector< vector<int> > ls(M);
	for (int i = 0; i < N; ++i) {
		cin >> K;
		for (int j = 0; j < K; ++j) {
			cin >> temp;
			ps[i].push_back(temp-1);
			ls[temp-1].push_back(i);
		}
	}

	vector<bool> spkp(N,false);
	vector<bool> spkl(M,false);
	bool nf = true;
	bool mode = true;
	int pn,ln;
	queue<int> pars,lang;
	pars.push(0);
	while (nf) {
		nf = false;
		if (mode) {
			while (!pars.empty()) {
				pn = pars.front();
				pars.pop();
				for (size_t i = 0; i < ps[pn].size(); ++i) {
					if (!spkl[ps[pn][i]]) {
						nf = true;
						lang.push(ps[pn][i]);
						spkl[ps[pn][i]] = true;
					}
				}
			}
		}
		else {
			while (!lang.empty()) {
				ln = lang.front();
				lang.pop();
				for (size_t i = 0; i < ls[ln].size(); ++i) {
					if (!spkp[ls[ln][i]]) {
						nf = true;
						pars.push(ls[ln][i]);
						spkp[ls[ln][i]] = true;
					}
				}
			}
		}
		mode = !mode;
	}

	bool find = false;
	for (int i = 0; !find && i < N; ++i) {
		if (!spkp[i]) {
			find = true;
		}
	}

	if (find) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User yumemoto
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1306 Byte
Status AC
Exec Time 59 ms
Memory 8952 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 2 ms 256 KB
01-03.txt AC 2 ms 384 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 2 ms 256 KB
01-06.txt AC 2 ms 256 KB
01-07.txt AC 2 ms 256 KB
01-08.txt AC 2 ms 256 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 2 ms 384 KB
02-01.txt AC 46 ms 5504 KB
02-02.txt AC 50 ms 6400 KB
02-03.txt AC 44 ms 3840 KB
02-04.txt AC 59 ms 7040 KB
02-05.txt AC 53 ms 5760 KB
02-06.txt AC 57 ms 7040 KB
02-07.txt AC 56 ms 6144 KB
02-08.txt AC 40 ms 6392 KB
02-09.txt AC 57 ms 8952 KB
02-10.txt AC 45 ms 6520 KB
02-11.txt AC 45 ms 6392 KB
02-12.txt AC 46 ms 6016 KB
02-13.txt AC 45 ms 6144 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB