# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129111 | SamAnd | Political Development (BOI17_politicaldevelopment) | C++17 | 161 ms | 9336 KiB |
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;
const int N = 50004, K = 12;
int n, k;
vector<int> a[N];
bool c[N];
int q[N];
int f[1 << K];
int qq[1 << K];
void pre()
{
for (int x = 1; x < (1 << k); ++x)
{
int yq = 0;
for (int i = 0; i < k; ++i)
{
if ((x & (1 << i)))
{
f[x] = i;
++yq;
}
}
qq[x] = yq;
}
}
vector<int> v;
int xx[K];
bool dp[1 << K];
int stg()
{
memset(xx, 0, sizeof xx);
for (int i = 0; i < v.size(); ++i)
{
for (int j = 0; j < v.size(); ++j)
{
if (binary_search(a[v[i]].begin(), a[v[i]].end(), v[j]))
xx[i] |= (1 << j);
}
}
memset(dp, false, sizeof dp);
dp[0] = true;
int ans = 0;
for (int x = 1; x < (1 << v.size()); ++x)
{
int i = f[x];
int y = (x ^ (1 << i));
if (dp[y] && (xx[i] & y) == y)
{
dp[x] = true;
ans = max(ans, qq[x]);
}
}
return ans;
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i)
{
int s;
scanf("%d", &s);
while (s--)
{
int x;
scanf("%d", &x);
a[i].push_back(x);
}
}
queue<int> s;
for (int i = 0; i < n; ++i)
{
sort(a[i].begin(), a[i].end());
q[i] = a[i].size();
if (q[i] <= k)
s.push(i);
}
pre();
int ans = 1;
while (1)
{
v.clear();
int x;
do
{
x = s.front();
s.pop();
if (s.empty())
{
cout << ans << endl;
return 0;
}
} while (c[x]);
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (c[h])
continue;
v.push_back(h);
--q[h];
if (q[h] <= k)
s.push(h);
}
ans = max(ans, stg() + 1);
c[x] = true;
}
return 0;
}
Compilation message (stderr)
# | 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... |