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 ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
const int N = 5e4 + 10;
unordered_set<int> st[N];
int ans = 1;
vector<int> adj[N];
bool vis[N];
void dfs(int u, set<int> nodes) {
ans = max(sz(nodes), ans);
vis[u] = true;
for(int v: adj[u]) {
if(vis[v]) continue;
set<int> newset = nodes; newset.insert(v);
for(auto x: nodes) if(st[v].find(x) == st[v].end()) newset.erase(x);
dfs(v, newset);
}
}
void solve() {
int n, k; cin >> n >> k;
for(int i = 0; i < n; ++i) {
int x; cin >> x;
if(x >= 1) {
adj[i].resize(x);
for(int j = 0; j < x; ++j) {
cin >> adj[i][j];
st[i].insert(adj[i][j]);
st[adj[i][j]].insert(i);
}
}
}
/*
for(int i = 0; i < n; ++i) {
if(sz(adj[i]) >= k) continue;
vector<int> dp(1 << (sz(adj[i])), 0);
dp[0] = 1;
for(int mask = 0; mask < (1 << (sz(adj[i]))); ++mask) {
if(!dp[mask]) continue;
int cnt = 1;
for(int f = 0; f < sz(adj[i]); ++f) {
if(mask >> f & 1) ++cnt;
}
ans = max(ans, cnt);
for(int j = 0; j < sz(adj[i]); ++j) {
if(mask >> j & 1) continue;
bool check = true;
for(int f = 0; f < sz(adj[i]); ++f) {
if(mask >> f & 1) {
if(st[adj[i][j]].find(adj[i][f]) == st[adj[i][j]].end()) check = false;
}
}
if(check) dp[mask | (1 << j)] = 1;
}
}
}
if(ans == k) {
cout << ans;
return;
}
*/
for(int i = 0; i < n; ++i) {
if(!vis[i]) dfs(i, {i});
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# | 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... |