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;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<set<int>> graph(N);
set<pair<int, int>> nodes;
set<pair<int, int>> edges;
for (int node = 0; node < N; node++) {
int degree;
cin >> degree;
nodes.emplace(degree, node);
for (int j = 0; j < degree; j++) {
int neighbour;
cin >> neighbour;
edges.emplace(node, neighbour);
graph[node].insert(neighbour);
}
}
vector<int> to(N, -1);
int answer = 0;
while (!nodes.empty()) {
auto [degree, node] = *nodes.begin();
nodes.erase({degree, node});
vector<int> neighbours;
to[node] = 0;
for (int i = 0; i < degree; i++) {
int neighbour = *graph[node].begin();
nodes.erase({(int)graph[neighbour].size(), neighbour});
graph[node].erase(neighbour);
graph[neighbour].erase(node);
nodes.emplace((int)graph[neighbour].size(), neighbour);
to[neighbour] = 1 + i;
neighbours.push_back(neighbour);
}
vector<int16_t> small_graph(degree + 1);
small_graph[to[node]] = (1 << (degree + 1)) - 1;
for (int x : neighbours) {
small_graph[to[x]] |= 1 << to[x];
small_graph[to[x]] |= 1 << to[node];
for (int y : neighbours) {
if (edges.count({x, y})) {
small_graph[to[x]] |= 1 << to[y];
}
}
}
for (int clique = 0; clique < (1 << degree); clique++) {
int16_t intersection = small_graph[to[node]];
for (int vertex = 1; vertex < degree + 1; vertex++) {
if ((clique >> (vertex - 1)) & 1) {
intersection &= small_graph[vertex];
}
}
if (((clique << 1) | 1) == intersection) {
answer = max(answer, __builtin_popcount(intersection));
}
}
to[node] = -1;
for (int neighbour : neighbours) {
to[neighbour] = -1;
}
}
cout << answer << "\n";
}
# | 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... |