This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
int N, K; cin >> N >> K;
vvi graph(N);
vi d(N);
vector<bool> del(N);
queue<int> q;
for (int i = 0; i < N; ++i) {
graph[i].push_back(i);
cin >> d[i];
for (int j = 0; j < d[i]; ++j) {
int x; cin >> x;
graph[i].push_back(x);
}
if (d[i] < K) q.push(i);
}
int ans = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
vi p;
for (int v : graph[u]) if (!del[v]) p.push_back(v);
int s = p.size();
vi p_idx(s);
for (int i = 0; i < s; ++i) p_idx[p[i]] = i;
vector<int> m(s);
for (int i = 0; i < s; ++i) for (int j : graph[i]) m[i] |= 1 << p_idx[j];
for (int c = 1; c < 1 << s; ++c) {
bool valid = true;
for (int i = 0; i < s; ++i) {
if (c & (1 << i) && (c & !m[i])) {
valid = false;
break;
}
}
if (valid) ans = max(ans, __builtin_popcount(c));
}
del[u] = true;
for (int v : graph[u]) if (--d[v] == K - 1) q.push(v);
}
cout << ans << endl;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |