Submission #547549

# Submission time Handle Problem Language Result Execution time Memory
547549 2022-04-10T23:23:31 Z skittles1412 Friends (BOI17_friends) C++17
69 / 100
228 ms 1084 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

const int maxn = 2505;

//#define STRESS

void fail() {
	cout << "detention" << endl;
	exit(0);
}

void print(const vector<vector<int>>& ans) {
#ifndef STRESS
	cout << sz(ans) << endl;
	for (auto& a : ans) {
		cout << sz(a);
		for (auto& b : a) {
			cout << " " << b;
		}
		cout << endl;
	}
#endif
}

bool found;
int n, p, q, decided[maxn];
vector<int> graph[maxn], cans, incl;

void dfs() {
	if (found || sz(incl) > p) {
		return;
	}
	int cq = 0;
	for (auto& a : incl) {
		for (auto& v : graph[a]) {
			if (!decided[v]) {
				{
					decided[v] = 1;
					incl.push_back(v);
					dfs();
					incl.pop_back();
					decided[v] = 0;
				}
				{
					decided[v] = -1;
					dfs();
					decided[v] = 0;
				}
				return;
			} else if (decided[v] == -1) {
				if (++cq > q) {
					return;
				}
			}
		}
	}
	cans = incl;
	found = true;
}

void solve() {
	cin >> n >> p >> q;
	for (int i = 0; i < n; i++) {
		auto& a = graph[i];
		int m;
		cin >> m;
		if (m > p + q - 1) {
			fail();
		}
		a.resize(m);
		for (auto& b : a) {
			cin >> b;
		}
	}
	for (int i = 0; i < n; i++) {
		for (auto& v : graph[i]) {
			auto& gv = graph[v];
			if (find(begin(gv), end(gv), i) == gv.end()) {
				fail();
			}
		}
	}
	set<int> blocks[n];
	for (int i = 0; i < n; i++) {
		incl = {i};
		decided[i] = 1;
		found = false;
		dfs();
		decided[i] = 0;
		if (!found) {
			fail();
		}
		blocks[i].insert(begin(cans), end(cans));
		dbg(i);
		for (auto& a : blocks[i]) {
			cerr << a << " ";
		}
		cerr << endl;
	}
	auto excl = [&](set<int> a, const set<int>& b) -> set<int> {
		for (auto& x : b) {
			a.erase(x);
		}
		return a;
	};
	auto check = [&](const set<int>& arr) -> bool {
		static int vis[maxn] {}, vind = 0;
		vind++;
		if (sz(arr) > p) {
			return false;
		}
		int cnt = 0;
		for (auto& a : arr) {
			vis[a] = vind;
		}
		for (auto& a : arr) {
			for (auto& b : graph[a]) {
				if (vis[b] != vind) {
					vis[b] = vind;
					if (++cnt > q) {
						return false;
					}
				}
			}
		}
		return true;
	};
	for (int i = 0; i < n; i++) {
		auto& a = blocks[i];
		for (int j = i + 1; j < n; j++) {
			auto& b = blocks[j];
			auto x = excl(a, b);
			if (check(x)) {
				a = x;
			} else {
				b = excl(b, a);
				assert(check(b));
			}
		}
	}
	vector<vector<int>> ans;
	for (auto& a : blocks) {
		assert(check(a));
		if (sz(a)) {
			ans.emplace_back(begin(a), end(a));
		}
	}
	cout << "home" << endl;
	print(ans);
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 79 ms 932 KB Output is correct
11 Correct 98 ms 932 KB Output is correct
12 Correct 110 ms 1008 KB Output is correct
13 Correct 128 ms 1036 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 400 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 79 ms 932 KB Output is correct
19 Correct 98 ms 932 KB Output is correct
20 Correct 110 ms 1008 KB Output is correct
21 Correct 128 ms 1036 KB Output is correct
22 Correct 1 ms 452 KB Output is correct
23 Correct 1 ms 400 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 0 ms 392 KB Output is correct
26 Incorrect 228 ms 1084 KB Output isn't correct
27 Halted 0 ms 0 KB -