#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;
vector<pair<int, int>> edges;
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;
edges.emplace_back(i, 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) {
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);
}
}
}
vector<vector<int>> ans;
for (auto& a : blocks) {
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 |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 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 |
0 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 |
468 KB |
Output is correct |
6 |
Correct |
0 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 |
468 KB |
Output is correct |
6 |
Correct |
0 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 |
73 ms |
984 KB |
Output is correct |
11 |
Correct |
96 ms |
1016 KB |
Output is correct |
12 |
Correct |
108 ms |
1024 KB |
Output is correct |
13 |
Correct |
112 ms |
1052 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 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 |
0 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 |
468 KB |
Output is correct |
14 |
Correct |
0 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 |
73 ms |
984 KB |
Output is correct |
19 |
Correct |
96 ms |
1016 KB |
Output is correct |
20 |
Correct |
108 ms |
1024 KB |
Output is correct |
21 |
Correct |
112 ms |
1052 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
226 ms |
1112 KB |
Output is correct |
27 |
Correct |
171 ms |
1048 KB |
Output is correct |
28 |
Correct |
168 ms |
1068 KB |
Output is correct |
29 |
Correct |
30 ms |
620 KB |
Output is correct |
30 |
Correct |
50 ms |
688 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
814 ms |
1968 KB |
Output is correct |
34 |
Correct |
70 ms |
968 KB |
Output is correct |