#2327639

Solution for 2011: Gather the Maps! by minaminao

Source Code Status Test Cases
    Policy: public     Reviewed: 3    
00.02 sec    3116 KB    65 lines     1547 bytes    2017-05-20 05:25
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

bool a[55][33];

struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (sizeOf(x) < sizeOf(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int sizeOf(int x) { return -parent[root(x)]; }
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int n; cin >> n&&n;) {
		memset(a, 0, sizeof(a));
		rep(i, 0, n) {
			int f; cin >> f;
			rep(j, 0, f) {
				int d; cin >> d;
				a[i][d] = true;
			}
		}
		UnionFind uf(n);
		rep(i, 0, 31) {
			rep(j, 0, n) {
				if (!a[j][i])continue;
				rep(k, j + 1, n) {
					if (!a[k][i])continue;
					uf.unite(j, k);
				}
				if (uf.size == 1) {
					cout << i << endl;
					j = INF, i = INF;
				}
			}
		}
	}
	return 0;
}

Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 0/1 C++14 CPU: 00.02 sec Memory: 3116 KB Length: 1547 B 2017-05-20 05:25 2017-05-20 05:25
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Wrong Answer 00.02 sec 3116 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags