Submission #1889887


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> connection;

//サブ関数
//入力
void input() {
	cin >> N >> M;
	REP(i, N)connection.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) {
	for (auto var : L2P[lang]) {
		connectP2L(var);
	}
}

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

void calc() {
	connectP2L(0);
}

//出力
void output() {
	bool flag = true;
	for (auto var : connection) {
		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 200
Code Size 1878 Byte
Status TLE
Exec Time 2104 ms
Memory 11388 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 0 / 200
Status
AC × 2
AC × 12
AC × 23
TLE × 4
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 3 ms 384 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 5 ms 384 KB
02-01.txt AC 48 ms 5488 KB
02-02.txt AC 90 ms 10416 KB
02-03.txt AC 49 ms 4084 KB
02-04.txt AC 67 ms 7668 KB
02-05.txt AC 65 ms 8060 KB
02-06.txt AC 67 ms 9076 KB
02-07.txt AC 64 ms 7424 KB
02-08.txt TLE 2104 ms 8368 KB
02-09.txt TLE 2104 ms 11388 KB
02-10.txt TLE 2104 ms 8696 KB
02-11.txt TLE 2104 ms 9848 KB
02-12.txt AC 865 ms 7288 KB
02-13.txt AC 863 ms 7160 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB