이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int n, p, q, group;
vector <vector <int>> taken;
vector <set <int>> adj;
int mask;
bool backtrack(int groupNo) {
if (groupNo == group) {
assert(mask == (1<<n)-1);
for(int i = 0; i < group; ++i) {
for(int j = i+1; j < group; ++j) {
int cnt = 0;
for(int x : taken[i]) {
for(int y : taken[j]) {
if (adj[x].find(y) != adj[x].end()) cnt++;
}
}
if (cnt > q) return false;
}
}
cout << "home\n" << group << '\n';
for(int i = 0; i < group; ++i) {
cout << taken[i].size() << ' ';
for(int x : taken[i]) cout << x << ' ';
cout << '\n';
}
return true;
}
int need = (n % p && groupNo == n-1? n % p:p);
for(int i = 1; i < (1<<n); ++i) {
if ((mask & i) != 0 || __builtin_popcount(i) != need) continue;
mask ^= i;
for(int j = 0; j < n; ++j) {
if (i & (1<<j)) {
taken[groupNo].push_back(j);
}
}
if (backtrack(groupNo+1)) return true;
mask ^= i;
taken[groupNo].clear();
}
return false;
}
int main(const int argc, const char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> p >> q;
group = (n + p-1) /p;
adj.resize(n);
taken.resize(n);
for(int i = 0; i < n; ++i) {
int x;
cin >> x;
while (x--) {
int a;
cin >> a;
adj[i].insert(a);
}
}
for(int i = 0; i < n; ++i) {
for(int j = i+1; j < n; ++j) {
bool f1 = adj[i].find(j) != adj[i].end();
bool f2 = adj[j].find(i) != adj[j].end();
if (f1 ^ f2) {
cout << "detention";
return 0;
}
}
}
if (!backtrack(0)) {
cout << "detention";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |