// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a, b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a, b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 5e4 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
set<int> adj[N];
void solve(int test_case)
{
int n,k; cin >> n >> k;
rep(i,n){
int s; cin >> s;
rep(j,s){
int v; cin >> v;
adj[i].insert(v);
}
adj[i].insert(i);
}
set<pii> st;
rep(i,n){
int d = sz(adj[i]);
st.insert({d,i});
}
vector<bool> dp(1<<(k+1));
int ans = 0;
while(!st.empty()){
auto [d,s] = *st.begin();
st.erase(st.begin());
assert(d <= k);
vector<int> nodes(all(adj[s]));
int siz = sz(nodes);
fill(all(dp),0);
dp[0] = 1;
rep1(mask,(1<<siz)-1){
int msb = -1;
rev(bit,siz-1,0){
if(mask & (1<<bit)){
msb = bit;
break;
}
}
int u = nodes[msb];
bool ok = true;
rep(i,siz){
if(mask & (1<<i)){
int v = nodes[i];
if(!adj[u].count(v)){
ok = false;
break;
}
}
}
if(ok){
dp[mask] = dp[mask^(1<<msb)];
}
}
rep(mask,1<<siz){
if(dp[mask]){
int cnt = setbits(mask);
amax(ans,cnt);
}
}
trav(v,adj[s]){
if(v == s) conts;
int d2 = sz(adj[v]);
st.erase({d2,v});
adj[v].erase(s);
d2--;
st.insert({d2,v});
}
}
cout << ans << endl;
}
int main()
{
fastio;
int t = 1;
// cin >> t;
rep1(i, t) {
solve(i);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3540 KB |
Output is correct |
4 |
Correct |
5 ms |
3540 KB |
Output is correct |
5 |
Correct |
4 ms |
3540 KB |
Output is correct |
6 |
Correct |
5 ms |
3540 KB |
Output is correct |
7 |
Correct |
5 ms |
3540 KB |
Output is correct |
8 |
Correct |
2 ms |
3028 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3540 KB |
Output is correct |
4 |
Correct |
5 ms |
3540 KB |
Output is correct |
5 |
Correct |
4 ms |
3540 KB |
Output is correct |
6 |
Correct |
5 ms |
3540 KB |
Output is correct |
7 |
Correct |
5 ms |
3540 KB |
Output is correct |
8 |
Correct |
2 ms |
3028 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
5 ms |
3540 KB |
Output is correct |
12 |
Correct |
7 ms |
3540 KB |
Output is correct |
13 |
Correct |
1 ms |
2664 KB |
Output is correct |
14 |
Correct |
5 ms |
3540 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
3540 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
5 ms |
3540 KB |
Output is correct |
19 |
Correct |
2 ms |
3028 KB |
Output is correct |
20 |
Correct |
4 ms |
3284 KB |
Output is correct |
21 |
Correct |
5 ms |
3284 KB |
Output is correct |
22 |
Correct |
4 ms |
3156 KB |
Output is correct |
23 |
Correct |
6 ms |
3668 KB |
Output is correct |
24 |
Correct |
2 ms |
3028 KB |
Output is correct |
25 |
Correct |
6 ms |
3668 KB |
Output is correct |
26 |
Correct |
6 ms |
3668 KB |
Output is correct |
27 |
Correct |
5 ms |
3540 KB |
Output is correct |
28 |
Correct |
6 ms |
3676 KB |
Output is correct |
29 |
Correct |
5 ms |
3540 KB |
Output is correct |
30 |
Correct |
8 ms |
3768 KB |
Output is correct |
31 |
Correct |
7 ms |
3668 KB |
Output is correct |
32 |
Correct |
7 ms |
3724 KB |
Output is correct |
33 |
Correct |
6 ms |
3668 KB |
Output is correct |
34 |
Correct |
6 ms |
3668 KB |
Output is correct |
35 |
Correct |
4 ms |
3156 KB |
Output is correct |
36 |
Correct |
4 ms |
3156 KB |
Output is correct |
37 |
Correct |
4 ms |
3156 KB |
Output is correct |
38 |
Correct |
3 ms |
2900 KB |
Output is correct |
39 |
Correct |
3 ms |
2992 KB |
Output is correct |
40 |
Correct |
9 ms |
4052 KB |
Output is correct |
41 |
Correct |
3 ms |
2900 KB |
Output is correct |
42 |
Correct |
9 ms |
4052 KB |
Output is correct |
43 |
Correct |
9 ms |
4084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3028 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
387 ms |
28476 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
393 ms |
28488 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
420 ms |
28452 KB |
Output is correct |
16 |
Correct |
389 ms |
28484 KB |
Output is correct |
17 |
Correct |
395 ms |
28544 KB |
Output is correct |
18 |
Correct |
397 ms |
28480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3540 KB |
Output is correct |
4 |
Correct |
5 ms |
3540 KB |
Output is correct |
5 |
Correct |
4 ms |
3540 KB |
Output is correct |
6 |
Correct |
5 ms |
3540 KB |
Output is correct |
7 |
Correct |
5 ms |
3540 KB |
Output is correct |
8 |
Correct |
2 ms |
3028 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
5 ms |
3540 KB |
Output is correct |
12 |
Correct |
7 ms |
3540 KB |
Output is correct |
13 |
Correct |
1 ms |
2664 KB |
Output is correct |
14 |
Correct |
5 ms |
3540 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
3540 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
5 ms |
3540 KB |
Output is correct |
19 |
Correct |
2 ms |
3028 KB |
Output is correct |
20 |
Correct |
4 ms |
3284 KB |
Output is correct |
21 |
Correct |
5 ms |
3284 KB |
Output is correct |
22 |
Correct |
4 ms |
3156 KB |
Output is correct |
23 |
Correct |
6 ms |
3668 KB |
Output is correct |
24 |
Correct |
2 ms |
3028 KB |
Output is correct |
25 |
Correct |
6 ms |
3668 KB |
Output is correct |
26 |
Correct |
6 ms |
3668 KB |
Output is correct |
27 |
Correct |
5 ms |
3540 KB |
Output is correct |
28 |
Correct |
6 ms |
3676 KB |
Output is correct |
29 |
Correct |
5 ms |
3540 KB |
Output is correct |
30 |
Correct |
8 ms |
3768 KB |
Output is correct |
31 |
Correct |
7 ms |
3668 KB |
Output is correct |
32 |
Correct |
7 ms |
3724 KB |
Output is correct |
33 |
Correct |
6 ms |
3668 KB |
Output is correct |
34 |
Correct |
6 ms |
3668 KB |
Output is correct |
35 |
Correct |
4 ms |
3156 KB |
Output is correct |
36 |
Correct |
4 ms |
3156 KB |
Output is correct |
37 |
Correct |
4 ms |
3156 KB |
Output is correct |
38 |
Correct |
3 ms |
2900 KB |
Output is correct |
39 |
Correct |
3 ms |
2992 KB |
Output is correct |
40 |
Correct |
9 ms |
4052 KB |
Output is correct |
41 |
Correct |
3 ms |
2900 KB |
Output is correct |
42 |
Correct |
9 ms |
4052 KB |
Output is correct |
43 |
Correct |
9 ms |
4084 KB |
Output is correct |
44 |
Correct |
52 ms |
4980 KB |
Output is correct |
45 |
Correct |
1 ms |
2668 KB |
Output is correct |
46 |
Correct |
11 ms |
4088 KB |
Output is correct |
47 |
Correct |
21 ms |
5156 KB |
Output is correct |
48 |
Correct |
9 ms |
4124 KB |
Output is correct |
49 |
Correct |
21 ms |
5204 KB |
Output is correct |
50 |
Correct |
22 ms |
5076 KB |
Output is correct |
51 |
Correct |
106 ms |
7260 KB |
Output is correct |
52 |
Correct |
5 ms |
3668 KB |
Output is correct |
53 |
Correct |
109 ms |
7768 KB |
Output is correct |
54 |
Correct |
145 ms |
7784 KB |
Output is correct |
55 |
Correct |
12 ms |
3668 KB |
Output is correct |
56 |
Correct |
6 ms |
3576 KB |
Output is correct |
57 |
Correct |
3 ms |
3060 KB |
Output is correct |
58 |
Correct |
116 ms |
7720 KB |
Output is correct |
59 |
Correct |
8 ms |
4148 KB |
Output is correct |
60 |
Correct |
11 ms |
3672 KB |
Output is correct |
61 |
Correct |
8 ms |
4180 KB |
Output is correct |
62 |
Correct |
8 ms |
4088 KB |
Output is correct |
63 |
Correct |
55 ms |
5120 KB |
Output is correct |
64 |
Correct |
33 ms |
4948 KB |
Output is correct |
65 |
Correct |
8 ms |
4052 KB |
Output is correct |
66 |
Correct |
8 ms |
4180 KB |
Output is correct |
67 |
Correct |
43 ms |
5632 KB |
Output is correct |
68 |
Correct |
34 ms |
4948 KB |
Output is correct |
69 |
Correct |
11 ms |
4052 KB |
Output is correct |
70 |
Correct |
20 ms |
5008 KB |
Output is correct |
71 |
Correct |
42 ms |
5588 KB |
Output is correct |
72 |
Correct |
37 ms |
5428 KB |
Output is correct |
73 |
Correct |
6 ms |
3540 KB |
Output is correct |
74 |
Correct |
21 ms |
4916 KB |
Output is correct |
75 |
Correct |
41 ms |
5460 KB |
Output is correct |
76 |
Correct |
14 ms |
4536 KB |
Output is correct |
77 |
Correct |
50 ms |
6000 KB |
Output is correct |
78 |
Correct |
6 ms |
3540 KB |
Output is correct |
79 |
Correct |
24 ms |
4308 KB |
Output is correct |
80 |
Correct |
13 ms |
4400 KB |
Output is correct |
81 |
Correct |
49 ms |
6100 KB |
Output is correct |
82 |
Correct |
4 ms |
2936 KB |
Output is correct |
83 |
Correct |
25 ms |
4348 KB |
Output is correct |
84 |
Correct |
32 ms |
5460 KB |
Output is correct |
85 |
Correct |
3 ms |
3028 KB |
Output is correct |
86 |
Correct |
39 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3540 KB |
Output is correct |
4 |
Correct |
5 ms |
3540 KB |
Output is correct |
5 |
Correct |
4 ms |
3540 KB |
Output is correct |
6 |
Correct |
5 ms |
3540 KB |
Output is correct |
7 |
Correct |
5 ms |
3540 KB |
Output is correct |
8 |
Correct |
2 ms |
3028 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
3028 KB |
Output is correct |
11 |
Correct |
5 ms |
3540 KB |
Output is correct |
12 |
Correct |
7 ms |
3540 KB |
Output is correct |
13 |
Correct |
1 ms |
2664 KB |
Output is correct |
14 |
Correct |
5 ms |
3540 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
3540 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
5 ms |
3540 KB |
Output is correct |
19 |
Correct |
2 ms |
3028 KB |
Output is correct |
20 |
Correct |
4 ms |
3284 KB |
Output is correct |
21 |
Correct |
5 ms |
3284 KB |
Output is correct |
22 |
Correct |
4 ms |
3156 KB |
Output is correct |
23 |
Correct |
6 ms |
3668 KB |
Output is correct |
24 |
Correct |
2 ms |
3028 KB |
Output is correct |
25 |
Correct |
6 ms |
3668 KB |
Output is correct |
26 |
Correct |
6 ms |
3668 KB |
Output is correct |
27 |
Correct |
5 ms |
3540 KB |
Output is correct |
28 |
Correct |
6 ms |
3676 KB |
Output is correct |
29 |
Correct |
5 ms |
3540 KB |
Output is correct |
30 |
Correct |
8 ms |
3768 KB |
Output is correct |
31 |
Correct |
7 ms |
3668 KB |
Output is correct |
32 |
Correct |
7 ms |
3724 KB |
Output is correct |
33 |
Correct |
6 ms |
3668 KB |
Output is correct |
34 |
Correct |
6 ms |
3668 KB |
Output is correct |
35 |
Correct |
4 ms |
3156 KB |
Output is correct |
36 |
Correct |
4 ms |
3156 KB |
Output is correct |
37 |
Correct |
4 ms |
3156 KB |
Output is correct |
38 |
Correct |
3 ms |
2900 KB |
Output is correct |
39 |
Correct |
3 ms |
2992 KB |
Output is correct |
40 |
Correct |
9 ms |
4052 KB |
Output is correct |
41 |
Correct |
3 ms |
2900 KB |
Output is correct |
42 |
Correct |
9 ms |
4052 KB |
Output is correct |
43 |
Correct |
9 ms |
4084 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
177 ms |
22908 KB |
Output is correct |
46 |
Correct |
67 ms |
15316 KB |
Output is correct |
47 |
Correct |
172 ms |
23220 KB |
Output is correct |
48 |
Correct |
167 ms |
23148 KB |
Output is correct |
49 |
Correct |
48 ms |
12660 KB |
Output is correct |
50 |
Correct |
165 ms |
28400 KB |
Output is correct |
51 |
Correct |
172 ms |
23196 KB |
Output is correct |
52 |
Correct |
51 ms |
12708 KB |
Output is correct |
53 |
Correct |
45 ms |
12720 KB |
Output is correct |
54 |
Correct |
17 ms |
7412 KB |
Output is correct |
55 |
Correct |
182 ms |
28444 KB |
Output is correct |
56 |
Correct |
30 ms |
10076 KB |
Output is correct |
57 |
Correct |
50 ms |
12716 KB |
Output is correct |
58 |
Correct |
60 ms |
15276 KB |
Output is correct |
59 |
Correct |
29 ms |
10056 KB |
Output is correct |
60 |
Correct |
30 ms |
10056 KB |
Output is correct |
61 |
Correct |
58 ms |
15280 KB |
Output is correct |
62 |
Correct |
53 ms |
12712 KB |
Output is correct |
63 |
Correct |
89 ms |
16604 KB |
Output is correct |
64 |
Correct |
30 ms |
9968 KB |
Output is correct |
65 |
Correct |
123 ms |
19212 KB |
Output is correct |
66 |
Correct |
46 ms |
12680 KB |
Output is correct |
67 |
Correct |
90 ms |
16652 KB |
Output is correct |
68 |
Correct |
116 ms |
18576 KB |
Output is correct |
69 |
Correct |
116 ms |
19284 KB |
Output is correct |
70 |
Correct |
47 ms |
12644 KB |
Output is correct |
71 |
Correct |
120 ms |
18644 KB |
Output is correct |
72 |
Correct |
90 ms |
16224 KB |
Output is correct |
73 |
Correct |
133 ms |
20952 KB |
Output is correct |
74 |
Correct |
49 ms |
12628 KB |
Output is correct |
75 |
Correct |
44 ms |
10172 KB |
Output is correct |
76 |
Correct |
86 ms |
16204 KB |
Output is correct |
77 |
Correct |
134 ms |
20852 KB |
Output is correct |
78 |
Correct |
69 ms |
11792 KB |
Output is correct |
79 |
Correct |
44 ms |
10068 KB |
Output is correct |
80 |
Correct |
25 ms |
6416 KB |
Output is correct |
81 |
Correct |
61 ms |
11716 KB |
Output is correct |
82 |
Correct |
97 ms |
17868 KB |
Output is correct |
83 |
Correct |
21 ms |
6356 KB |
Output is correct |
84 |
Correct |
98 ms |
17856 KB |
Output is correct |