이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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()
void solve() {
int n, k; cin >> n >> k;
unordered_set<int> st[n + 1];
vector<vector<int>> adj(n);
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);
}
}
}
int ans = 1;
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;
}
}
}
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... |