# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
841299 | serifefedartar | Political Development (BOI17_politicaldevelopment) | C++17 | 3077 ms | 28048 KiB |
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;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 50005
vector<set<int>> graph;
int deg[MAXN];
int main() {
fast
int N, K, x, D;
cin >> N >> K;
graph = vector<set<int>>(N, set<int>());
queue<int> q;
for (int i = 0; i < N; i++) {
cin >> deg[i];
for (int j = 0; j < deg[i]; j++) {
cin >> x;
graph[i].insert(x);
}
if (deg[i] < K)
q.push(i);
}
int ans = 1;
while (!q.empty()) {
int node = q.front();
q.pop();
int degree = graph[node].size();
vector<int> adj;
for (auto u : graph[node])
adj.push_back(u);
int mx_mask = (1<<degree) - 1;
for (int msk = 1; msk <= mx_mask; msk++) {
int k = __builtin_popcount(msk);
if (k + 1 <= ans)
continue;
vector<int> taken;
taken.push_back(node);
bool check = true;
for (int j = 0; j < degree; j++) {
if ((1<<j) & msk) {
for (auto u : taken) {
if (graph[adj[j]].count(u) == 0)
check = false;
}
taken.push_back(adj[j]);
}
}
if (check)
ans = max(ans, k + 1);
}
for (auto u : graph[node]) {
graph[u].erase(node);
deg[u]--;
if (deg[u] < K)
q.push(u);
}
}
cout << ans << "\n";
}
Compilation message (stderr)
# | 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... |