#include <bits/stdc++.h>
using namespace std;
int deg[50005];
vector<int> adj[50005];
set<pair<int, int>> s;
vector<int> neighbours;
bool erased[50005];
int ans = 0;
int sz;
bool check(int mask) {
for (int i = 0; i < sz; i++) {
if ((1 << i) & mask) {
for (int j = 0; j < i; j++) {
if (( 1 << j ) & mask) {
int a = neighbours[i], b = neighbours[j];
if (*lower_bound(adj[a].begin(), adj[a].end(), b) != b) return false;
}
}
}
}
return true;
}
int main() {
int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> deg[i];
s.insert({deg[i], i});
for (int _ = 0; _ < deg[i]; _++) {
int to; cin >> to;
adj[i].push_back(to);
}
sort(adj[i].begin(), adj[i].end());
}
for (int i = 0; i < n; i++) {
auto cur = *s.begin();
s.erase(s.begin());
if (cur.first == 0) {
erased[cur.second] = true;
continue;
}
neighbours.clear();
neighbours.push_back(cur.second);
for (auto nxt : adj[cur.second]) {
if (erased[nxt]) continue;
neighbours.push_back(nxt);
}
sz = neighbours.size();
for (int mask = (1 << sz) - 1; mask >= (1 << ans); mask--) {
if (__builtin_popcount(mask) <= ans) continue;
if (check(mask)) ans = __builtin_popcount(mask);
}
for (auto nxt : adj[cur.second]) {
if (erased[nxt]) continue;
s.erase({deg[nxt], nxt}); deg[nxt]--;
s.insert({deg[nxt], nxt});
}
erased[cur.second] = true;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1488 KB |
Output is correct |
3 |
Correct |
8 ms |
1876 KB |
Output is correct |
4 |
Correct |
7 ms |
1908 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
6 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1892 KB |
Output is correct |
8 |
Incorrect |
3 ms |
1748 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1488 KB |
Output is correct |
3 |
Correct |
8 ms |
1876 KB |
Output is correct |
4 |
Correct |
7 ms |
1908 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
6 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1892 KB |
Output is correct |
8 |
Incorrect |
3 ms |
1748 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1488 KB |
Output is correct |
3 |
Correct |
8 ms |
1876 KB |
Output is correct |
4 |
Correct |
7 ms |
1908 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
6 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1892 KB |
Output is correct |
8 |
Incorrect |
3 ms |
1748 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1488 KB |
Output is correct |
3 |
Correct |
8 ms |
1876 KB |
Output is correct |
4 |
Correct |
7 ms |
1908 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
6 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1892 KB |
Output is correct |
8 |
Incorrect |
3 ms |
1748 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |