CODE FESTIVAL 2016 Final

Submission #7922934

Source codeソースコード

#include <iostream>
#include <vector>

using namespace std;
struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) {
		if(par[x] == x) return x;
			//ここで併合処理も行なっている
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

};


int main() {
	int N;
	cin >> N;
	UnionFind a(N);
	int M;
	cin >> M;
	vector<vector<bool> > L(N, vector<bool>(M, false));

	for(int i = 0; i < N; i++) {
		int ki;
		cin >> ki;
		for(int j = 0; j < ki; j++) {
			int x;
			cin >> x;
			L[i][x - 1] = true;
		}
	}

	for(int l = 0; l < M; l++) {
		int first_hit = -1;
		for(int i = 0; i < N; i++) {
			if(L[i][l] == true) {
				if(first_hit == -1) first_hit = i;
				else a.unite(first_hit, i);
			}
		}
	}

	for(int i = 0; i < N; i++) {
		for(int j = i + 1; j < N; j++) {
			if(a.same(i, j) == false) {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
}

Submission

Task問題 C - Interpretation
User nameユーザ名 STN
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 TLE
Score得点 200
Source lengthソースコード長 1207 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
dataset1 200 / 200 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 0 / 200 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 1 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 4 ms 384 KB
01-04.txt AC 7 ms 384 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 5 ms 384 KB
01-07.txt AC 4 ms 256 KB
01-08.txt AC 3 ms 384 KB
01-09.txt AC 5 ms 384 KB
01-10.txt AC 9 ms 512 KB
02-01.txt TLE
02-02.txt AC 437 ms 16512 KB
02-03.txt TLE
02-04.txt TLE
02-05.txt TLE
02-06.txt TLE
02-07.txt TLE
02-08.txt AC 104 ms 7680 KB
02-09.txt TLE
02-10.txt TLE
02-11.txt TLE
02-12.txt TLE
02-13.txt TLE
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB