#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int MAXN = 5e4 + 7 ;
int n , k ;
int sz[ MAXN ] ;
set < int > s[ MAXN ] ;
bool done[ MAXN ] ;
priority_queue < pair < int , int > > q ;
vector < int > v ;
bool adj[ 12 ][ 12 ] ;
bool valid[ ( 1 << 12 ) ] ;
int f ( ) {
int len = v.size ( ) ;
for ( int i = 0 ; i < len ; ++ i ) {
int x = v[ i ] ;
for ( int j = 0 ; j < len ; ++ j ) {
int y = v[ j ] ;
if ( s[ x ].find ( y ) != s[ x ].end ( ) ) {
adj[ i ][ j ] = true ;
}
else {
adj[ i ][ j ] = false ;
}
}
}
for ( int i = 0 ; i < ( 1 << len ) ; ++ i ) {
valid[ i ] = false ;
}
valid[ 0 ] = true ;
for ( int i = 0 ; i < len ; ++ i ) {
for ( int mask = 0 ; mask < ( 1 << i ) ; ++ mask ) {
if ( valid[ mask ] == false ) { continue ; }
valid[ mask + ( 1 << i ) ] = true ;
for ( int t = 0 ; t < i ; ++ t ) {
if ( ( mask & ( 1 << t ) ) > 0 ) {
if ( adj[ t ][ i ] == false ) {
valid[ mask + ( 1 << i ) ] = false ;
break ;
}
}
}
}
}
int ret = 0 ;
for ( int i = 0 ; i < ( 1 << len ) ; ++ i ) {
if ( valid[ i ] == true ) {
ret = max ( ret , __builtin_popcount ( i ) ) ;
}
}
return ret ;
}
void solve ( ) {
cin >> n >> k ;
for ( int i = 1 ; i <= n ; ++ i ) {
cin >> sz[ i ] ;
for ( int j = 0 , x ; j < sz[ i ] ; ++ j ) {
cin >> x ; ++ x ;
s[ i ].insert ( x ) ;
}
if ( sz[ i ] <= k ) {
q.push ( { -sz[ i ] , i } ) ;
}
}
int ans = 0 ;
while ( q.empty ( ) == false ) {
auto [ c , wh ] = q.top ( ) ;
q.pop ( ) ;
c = -c ;
if ( done[ wh ] == true || c != sz[ wh ] ) { continue ; }
done[ wh ] = true ;
v.clear ( ) ;
for ( auto x : s[ wh ] ) {
if ( done[ x ] == false ) {
v.push_back ( x ) ;
-- sz[ x ] ;
if ( sz[ x ] <= k ) {
q.push ( { -sz[ x ] , x } ) ;
}
}
}
ans = max ( ans , f ( ) + 1 ) ;
}
cout << ans << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; // cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3220 KB |
Output is correct |
4 |
Correct |
4 ms |
3156 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3220 KB |
Output is correct |
4 |
Correct |
4 ms |
3156 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
3156 KB |
Output is correct |
12 |
Correct |
4 ms |
3156 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
5 ms |
3284 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
3284 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
5 ms |
3284 KB |
Output is correct |
19 |
Correct |
2 ms |
2772 KB |
Output is correct |
20 |
Correct |
3 ms |
2964 KB |
Output is correct |
21 |
Correct |
3 ms |
3028 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
5 ms |
3356 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
7 ms |
3416 KB |
Output is correct |
26 |
Correct |
5 ms |
3288 KB |
Output is correct |
27 |
Correct |
4 ms |
3276 KB |
Output is correct |
28 |
Correct |
8 ms |
3344 KB |
Output is correct |
29 |
Correct |
4 ms |
3284 KB |
Output is correct |
30 |
Correct |
6 ms |
3412 KB |
Output is correct |
31 |
Correct |
9 ms |
3452 KB |
Output is correct |
32 |
Correct |
6 ms |
3412 KB |
Output is correct |
33 |
Correct |
6 ms |
3460 KB |
Output is correct |
34 |
Correct |
5 ms |
3344 KB |
Output is correct |
35 |
Correct |
3 ms |
3028 KB |
Output is correct |
36 |
Correct |
4 ms |
2952 KB |
Output is correct |
37 |
Correct |
3 ms |
2960 KB |
Output is correct |
38 |
Correct |
3 ms |
2900 KB |
Output is correct |
39 |
Correct |
3 ms |
2900 KB |
Output is correct |
40 |
Correct |
7 ms |
3668 KB |
Output is correct |
41 |
Correct |
3 ms |
2956 KB |
Output is correct |
42 |
Correct |
8 ms |
3796 KB |
Output is correct |
43 |
Correct |
8 ms |
3768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2592 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2684 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
201 ms |
28692 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
234 ms |
28676 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
209 ms |
28656 KB |
Output is correct |
16 |
Correct |
214 ms |
28716 KB |
Output is correct |
17 |
Correct |
206 ms |
28728 KB |
Output is correct |
18 |
Correct |
209 ms |
28732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3220 KB |
Output is correct |
4 |
Correct |
4 ms |
3156 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
3156 KB |
Output is correct |
12 |
Correct |
4 ms |
3156 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
5 ms |
3284 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
3284 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
5 ms |
3284 KB |
Output is correct |
19 |
Correct |
2 ms |
2772 KB |
Output is correct |
20 |
Correct |
3 ms |
2964 KB |
Output is correct |
21 |
Correct |
3 ms |
3028 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
5 ms |
3356 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
7 ms |
3416 KB |
Output is correct |
26 |
Correct |
5 ms |
3288 KB |
Output is correct |
27 |
Correct |
4 ms |
3276 KB |
Output is correct |
28 |
Correct |
8 ms |
3344 KB |
Output is correct |
29 |
Correct |
4 ms |
3284 KB |
Output is correct |
30 |
Correct |
6 ms |
3412 KB |
Output is correct |
31 |
Correct |
9 ms |
3452 KB |
Output is correct |
32 |
Correct |
6 ms |
3412 KB |
Output is correct |
33 |
Correct |
6 ms |
3460 KB |
Output is correct |
34 |
Correct |
5 ms |
3344 KB |
Output is correct |
35 |
Correct |
3 ms |
3028 KB |
Output is correct |
36 |
Correct |
4 ms |
2952 KB |
Output is correct |
37 |
Correct |
3 ms |
2960 KB |
Output is correct |
38 |
Correct |
3 ms |
2900 KB |
Output is correct |
39 |
Correct |
3 ms |
2900 KB |
Output is correct |
40 |
Correct |
7 ms |
3668 KB |
Output is correct |
41 |
Correct |
3 ms |
2956 KB |
Output is correct |
42 |
Correct |
8 ms |
3796 KB |
Output is correct |
43 |
Correct |
8 ms |
3768 KB |
Output is correct |
44 |
Correct |
17 ms |
4748 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Correct |
8 ms |
3668 KB |
Output is correct |
47 |
Correct |
15 ms |
4816 KB |
Output is correct |
48 |
Correct |
8 ms |
3796 KB |
Output is correct |
49 |
Correct |
15 ms |
4820 KB |
Output is correct |
50 |
Correct |
15 ms |
4932 KB |
Output is correct |
51 |
Correct |
33 ms |
6884 KB |
Output is correct |
52 |
Correct |
4 ms |
3188 KB |
Output is correct |
53 |
Correct |
39 ms |
7352 KB |
Output is correct |
54 |
Correct |
44 ms |
7388 KB |
Output is correct |
55 |
Correct |
5 ms |
3284 KB |
Output is correct |
56 |
Correct |
6 ms |
3216 KB |
Output is correct |
57 |
Correct |
2 ms |
2772 KB |
Output is correct |
58 |
Correct |
39 ms |
7384 KB |
Output is correct |
59 |
Correct |
8 ms |
3796 KB |
Output is correct |
60 |
Correct |
5 ms |
3284 KB |
Output is correct |
61 |
Correct |
7 ms |
3668 KB |
Output is correct |
62 |
Correct |
7 ms |
3720 KB |
Output is correct |
63 |
Correct |
19 ms |
4800 KB |
Output is correct |
64 |
Correct |
13 ms |
4564 KB |
Output is correct |
65 |
Correct |
7 ms |
3672 KB |
Output is correct |
66 |
Correct |
10 ms |
3696 KB |
Output is correct |
67 |
Correct |
20 ms |
5280 KB |
Output is correct |
68 |
Correct |
13 ms |
4484 KB |
Output is correct |
69 |
Correct |
7 ms |
3592 KB |
Output is correct |
70 |
Correct |
13 ms |
4748 KB |
Output is correct |
71 |
Correct |
18 ms |
5184 KB |
Output is correct |
72 |
Correct |
24 ms |
5336 KB |
Output is correct |
73 |
Correct |
4 ms |
3272 KB |
Output is correct |
74 |
Correct |
14 ms |
4696 KB |
Output is correct |
75 |
Correct |
18 ms |
5208 KB |
Output is correct |
76 |
Correct |
13 ms |
4232 KB |
Output is correct |
77 |
Correct |
25 ms |
6016 KB |
Output is correct |
78 |
Correct |
4 ms |
3284 KB |
Output is correct |
79 |
Correct |
12 ms |
4308 KB |
Output is correct |
80 |
Correct |
10 ms |
4180 KB |
Output is correct |
81 |
Correct |
23 ms |
6032 KB |
Output is correct |
82 |
Correct |
3 ms |
2900 KB |
Output is correct |
83 |
Correct |
12 ms |
4388 KB |
Output is correct |
84 |
Correct |
18 ms |
5332 KB |
Output is correct |
85 |
Correct |
3 ms |
2900 KB |
Output is correct |
86 |
Correct |
17 ms |
5332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
5 ms |
3220 KB |
Output is correct |
4 |
Correct |
4 ms |
3156 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
4 ms |
3156 KB |
Output is correct |
12 |
Correct |
4 ms |
3156 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
5 ms |
3284 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
3284 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
5 ms |
3284 KB |
Output is correct |
19 |
Correct |
2 ms |
2772 KB |
Output is correct |
20 |
Correct |
3 ms |
2964 KB |
Output is correct |
21 |
Correct |
3 ms |
3028 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
5 ms |
3356 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
7 ms |
3416 KB |
Output is correct |
26 |
Correct |
5 ms |
3288 KB |
Output is correct |
27 |
Correct |
4 ms |
3276 KB |
Output is correct |
28 |
Correct |
8 ms |
3344 KB |
Output is correct |
29 |
Correct |
4 ms |
3284 KB |
Output is correct |
30 |
Correct |
6 ms |
3412 KB |
Output is correct |
31 |
Correct |
9 ms |
3452 KB |
Output is correct |
32 |
Correct |
6 ms |
3412 KB |
Output is correct |
33 |
Correct |
6 ms |
3460 KB |
Output is correct |
34 |
Correct |
5 ms |
3344 KB |
Output is correct |
35 |
Correct |
3 ms |
3028 KB |
Output is correct |
36 |
Correct |
4 ms |
2952 KB |
Output is correct |
37 |
Correct |
3 ms |
2960 KB |
Output is correct |
38 |
Correct |
3 ms |
2900 KB |
Output is correct |
39 |
Correct |
3 ms |
2900 KB |
Output is correct |
40 |
Correct |
7 ms |
3668 KB |
Output is correct |
41 |
Correct |
3 ms |
2956 KB |
Output is correct |
42 |
Correct |
8 ms |
3796 KB |
Output is correct |
43 |
Correct |
8 ms |
3768 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
105 ms |
19288 KB |
Output is correct |
46 |
Correct |
58 ms |
11176 KB |
Output is correct |
47 |
Correct |
123 ms |
19304 KB |
Output is correct |
48 |
Correct |
109 ms |
19264 KB |
Output is correct |
49 |
Correct |
33 ms |
8644 KB |
Output is correct |
50 |
Correct |
149 ms |
24360 KB |
Output is correct |
51 |
Correct |
113 ms |
19200 KB |
Output is correct |
52 |
Correct |
31 ms |
8568 KB |
Output is correct |
53 |
Correct |
36 ms |
8644 KB |
Output is correct |
54 |
Correct |
9 ms |
3544 KB |
Output is correct |
55 |
Correct |
144 ms |
24444 KB |
Output is correct |
56 |
Correct |
20 ms |
5964 KB |
Output is correct |
57 |
Correct |
32 ms |
8648 KB |
Output is correct |
58 |
Correct |
47 ms |
11204 KB |
Output is correct |
59 |
Correct |
22 ms |
5964 KB |
Output is correct |
60 |
Correct |
21 ms |
5964 KB |
Output is correct |
61 |
Correct |
46 ms |
11176 KB |
Output is correct |
62 |
Correct |
34 ms |
8648 KB |
Output is correct |
63 |
Correct |
70 ms |
12656 KB |
Output is correct |
64 |
Correct |
21 ms |
5964 KB |
Output is correct |
65 |
Correct |
89 ms |
15828 KB |
Output is correct |
66 |
Correct |
35 ms |
8660 KB |
Output is correct |
67 |
Correct |
65 ms |
12676 KB |
Output is correct |
68 |
Correct |
82 ms |
15124 KB |
Output is correct |
69 |
Correct |
84 ms |
15816 KB |
Output is correct |
70 |
Correct |
49 ms |
8652 KB |
Output is correct |
71 |
Correct |
88 ms |
15240 KB |
Output is correct |
72 |
Correct |
66 ms |
12048 KB |
Output is correct |
73 |
Correct |
100 ms |
17476 KB |
Output is correct |
74 |
Correct |
36 ms |
8580 KB |
Output is correct |
75 |
Correct |
35 ms |
8472 KB |
Output is correct |
76 |
Correct |
69 ms |
12224 KB |
Output is correct |
77 |
Correct |
123 ms |
17560 KB |
Output is correct |
78 |
Correct |
46 ms |
10008 KB |
Output is correct |
79 |
Correct |
33 ms |
8400 KB |
Output is correct |
80 |
Correct |
20 ms |
5332 KB |
Output is correct |
81 |
Correct |
46 ms |
10096 KB |
Output is correct |
82 |
Correct |
82 ms |
14564 KB |
Output is correct |
83 |
Correct |
16 ms |
5460 KB |
Output is correct |
84 |
Correct |
75 ms |
14512 KB |
Output is correct |