#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
#define ll long long
#define sped_up ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rall(v) (v).rbegin(), (v).rend()
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define S second
#define F first
const ll INF = (ll)1e9 + 1, INFL = (ll)1e18 + 1;
const ll mod = (ll)1e9 + 7, MAXN = (ll)5e3 + 1;
vector <ll> g[MAXN];
bool c[MAXN][MAXN];
bool used[MAXN];
ll col = 0;
void dfs (ll v) {
used[v] = 1;
bool ok = 1, ok1 = 0;
for (int i = 1; i <= col; i++) {
for (auto j : g[v]) {
if (c[i][j]) ok = 0;
}
c[i][v] = ok;
ok1 |= ok;
ok = 1;
}
if (!ok1) c[++col][v] = 1;
for (auto i : g[v]) {
if (!used[i]) {
dfs(i);
}
}
ok = 1;
for (int i = 1; i <= col; i++) {
for (auto j : g[v]) {
if (c[i][j]) ok = 0;
}
c[i][v] = ok;
ok = 1;
}
}
int main() {
sped_up;
ll n, k;
cin >> n >> k;
ll mx = 0;
for (int i = 1; i <= n; i++) {
ll a;
cin >> a;
for (int j = 1; j <= a; j++) {
ll b;
cin >> b;
c[i][b + 1] = 1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (c[i][j] == 0) g[i].pb(j);
c[i][j] = 0;
}
}
dfs(1);
for (int i = 1; i <= col; i++) {
ll cnt = 0;
for (int j = 1; j <= n; j++) cnt += c[i][j];
mx = max(mx, cnt);
}
cout << mx;
}
| # | 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... |