Submission #7923084


Source Code Expand

Copy
#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<int> > L(N);

	for(int i = 0; i < N; i++) {
		int ki;
		cin >> ki;
		L[i] = vector<int>(ki);
		for(int j = 0; j < ki; j++) {
			cin >> L[i][j];
		}
		sort(L[i].begin(), L[i].end());
	}

	for(int i = 0; i < N; i++) {
		int im = L[i].size();
		for(int j = i + 1; j < N; j++) {
			if(a.same(i, j) == true) continue;
			int ii = 0;
			int ji = 0;
			int jm = L[j].size();
			while(ii < im && ji < jm) {
				if(L[i][ii] == L[j][ji]) {
					a.unite(i, j);
					break;
				} else if(L[i][ii] < L[j][ji]) {
					ii++;
				} else {
					ji++;
				}
			}
		}
	}

	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 Info

Submission Time
Task C - Interpretation
User ssssttttnnnn
Language C++14 (Clang 3.8.0)
Score 200
Code Size 1400 Byte
Status
Exec Time 2104 ms
Memory 9216 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 0 / 200
Status
Test Cases sample-01.txt, sample-02.txt 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 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
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 1 ms 256 KB
01-02.txt 2 ms 256 KB
01-03.txt 8 ms 256 KB
01-04.txt 13 ms 384 KB
01-05.txt 8 ms 256 KB
01-06.txt 7 ms 256 KB
01-07.txt 6 ms 256 KB
01-08.txt 6 ms 256 KB
01-09.txt 8 ms 256 KB
01-10.txt 13 ms 384 KB
02-01.txt 579 ms 896 KB
02-02.txt 2104 ms 5888 KB
02-03.txt 1111 ms 1024 KB
02-04.txt 2103 ms 3584 KB
02-05.txt 2104 ms 4992 KB
02-06.txt 2103 ms 3584 KB
02-07.txt 2104 ms 5504 KB
02-08.txt 2104 ms 7680 KB
02-09.txt 2104 ms 9216 KB
02-10.txt 2103 ms 4992 KB
02-11.txt 2104 ms 4992 KB
02-12.txt 2103 ms 3456 KB
02-13.txt 2103 ms 3456 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB