이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// `Be name khoda` //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn5 = 2e5 + 10;
set <int> adjset[maxn5];
vector <int> adj[maxn5], ver;
priority_queue <pair<int, int>> av;
bool ed[20][20], mark[maxn5], dp[1 << 20];
int cnt[maxn5];
inline int max_indep(){
int n = ver.size();
assert(n <= 10);
memset(ed, false, sizeof ed);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++)
if(adjset[ver[i]].find(ver[j]) != adjset[ver[i]].end())
ed[i][j] = true;
dp[0] = true;
int ans = 0;
for(int mask = 1; mask < (1 << n); mask++){
int v = -1;
dp[mask] = true;
for(int i = 0; i < n; i++) if((mask >> i)&1){
if(v == -1){
v = i;
dp[mask] = dp[mask ^ (1 << i)];
}
else
dp[mask] &= ed[v][i];
}
if(dp[mask])
ans = max(ans, __builtin_popcount(mask));
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, k; cin >> n >> k;
for(int i = 0; i < n; i++){
int l; cin >> l;
cnt[i] = l;
while(l--){
int a; cin >> a;
adj[i].pb(a);
adjset[i].insert(a);
assert(a != i);
}
av.push({-cnt[i], i});
}
for(int i = 0; i < n; i++) for(auto u : adj[i])
assert(adjset[u].find(i) != adjset[u].end());
int ans = 0;
for(int i = 0; i < n; i++){
while(mark[av.top().se])
av.pop();
int v = av.top().se;
av.pop();
mark[v] = true;
ver.clear();
for(auto u : adj[v]) if(!mark[u]){
cnt[u]--;
av.push({-cnt[u], u});
ver.pb(u);
}
ans = max(ans, max_indep() + 1);
}
cout << ans << endl;
}
# | 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... |