Submission #1889891


Source Code Expand

#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
const int INF = (1 << 30);

//毎回変える定数
#define N_MAX 200


//問題文のとおりの変数
int N, M;

//オリジナル変数
vector<vector<int>> P2L;//人から言語への辺
vector<vector<int>> L2P;//言語から人への辺

vector<bool> connectionP;
vector<bool> connectionL;

//サブ関数
//入力
void input() {
	cin >> N >> M;
	REP(i, N)connectionP.push_back(false);
	REP(i, M)connectionL.push_back(false);
	REP(i, M)L2P.push_back(vector<int>());

	int K,tmp;
	REP(i, N) {
		vector<int> tmpL;
		cin >> K;
		REP(j, K) {
			cin >> tmp;
			tmp--;

			tmpL.push_back(tmp);//P2L
			L2P[tmp].push_back(i);//L2P
		}
		P2L.push_back(tmpL);
	}
}

//計算
void connectP2L(int);
void connectL2P(int lang) {
	if (connectionL[lang])return;
	connectionL[lang] = true;
	for (auto var : L2P[lang]) {
		connectP2L(var);
	}
}

void connectP2L(int person) {
	if (connectionP[person])return;
	connectionP[person] = true;
	for (auto var : P2L[person]) {
		connectL2P(var);
	}
}

void calc() {
	connectP2L(0);
}

//出力
void output() {
	bool flag = true;
	for (auto var : connectionP) {
		if (var == false) {
			flag = false;
			break;
		}
	}
	if (flag)cout << "YES" << endl;
	else cout << "NO" << endl;
}

//デバッグ
void debug() {
	cin >> N;
}

//メイン関数
int main() {

	input();
	calc();
	output();
	debug();

	return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User toma25
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2011 Byte
Status AC
Exec Time 68 ms
Memory 9212 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 384 KB
01-07.txt AC 2 ms 256 KB
01-08.txt AC 2 ms 384 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 2 ms 384 KB
02-01.txt AC 48 ms 5500 KB
02-02.txt AC 54 ms 7220 KB
02-03.txt AC 48 ms 4092 KB
02-04.txt AC 66 ms 7036 KB
02-05.txt AC 60 ms 7680 KB
02-06.txt AC 68 ms 7036 KB
02-07.txt AC 59 ms 6144 KB
02-08.txt AC 46 ms 6452 KB
02-09.txt AC 63 ms 9212 KB
02-10.txt AC 48 ms 6520 KB
02-11.txt AC 49 ms 6520 KB
02-12.txt AC 48 ms 6008 KB
02-13.txt AC 49 ms 6008 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB