#include<bits/stdc++.h>
using namespace std;
const int maxn=50000+10;
vector<int>adj[maxn];
int cnt[maxn],n,k,tartib[maxn],mask[maxn],msk[maxn],ind[maxn],lg[maxn];
void vorod(){
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>cnt[i];
adj[i].resize(cnt[i]);
for(int j=0;j<cnt[i];j++){
cin>>adj[i][j];
}
}
}
bool cmp(int a,int b){
return tartib[b]<tartib[a];
}
void pre(){
lg[1]=0;
for(int i=2;i<(1<<12);i++){
lg[i]=lg[i/2]+1;
}
vector<int>v;
for(int i=0;i<n;i++){
if(cnt[i]<k){
v.push_back(i);
}
}
for(int i=0;i<n;i++){
//cout<<v.size()<<" "<<v[i]<<endl;
tartib[v[i]]=i;
for(auto x:adj[v[i]]){
//cout<<"kam: "<<x<<" "<<i<<" "<<cnt[x]<<endl;
cnt[x]--;
if(cnt[x]==k-1){
v.push_back(x);
}
}
}
for(int i=0;i<n;i++){
sort(adj[i].begin(),adj[i].end(),cmp);
while((int)adj[i].size()>0&&tartib[adj[i].back()]<tartib[i]){
adj[i].pop_back();
}
}
}
int cal(int u){
//cout<<u<<" "<<(int)adj[u].size()<<" hey"<<endl;
for(int i=0;i<(int)adj[u].size();i++){
ind[adj[u][i]]=i;
}
for(int i=0;i<(int)adj[u].size();i++){
int v=adj[u][i];
msk[v]|=(1<<ind[v]);
for(auto x:adj[v]){
if(ind[x]==-1){
continue;
}
msk[v]|=(1<<ind[x]);
msk[x]|=(1<<ind[v]);
}
}
mask[0]=(1<<(int)adj[u].size())-1;
int ret=0;
for(int i=1;i<(1<<(int)adj[u].size());i++){
int w=(i&(-i));
int v=adj[u][lg[w]];
if(i!=w){
mask[i]=(mask[i^w]&msk[v]);
}else{
mask[i]=msk[v];
}
if((mask[i]&i)==i){
ret=max(ret,__builtin_popcount(i));
}
}
ret++;
for(auto x:adj[u]){
msk[x]=0;
ind[x]=-1;
}
return ret;
}
void solve(){
//cout<<"salam"<<endl;
int res=1;
for(int i=0;i<maxn;i++){
ind[i]=-1;
}
for(int i=0;i<n;i++){
res=max(res,cal(i));
}
cout<<res<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vorod();
pre();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2636 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2716 KB |
Output is correct |
28 |
Correct |
2 ms |
2740 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2768 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
2 ms |
2648 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2652 KB |
Output is correct |
4 |
Correct |
0 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
48 ms |
5244 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
51 ms |
5340 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
48 ms |
5292 KB |
Output is correct |
16 |
Correct |
47 ms |
5200 KB |
Output is correct |
17 |
Correct |
50 ms |
5212 KB |
Output is correct |
18 |
Correct |
48 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2636 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2716 KB |
Output is correct |
28 |
Correct |
2 ms |
2740 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2768 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
2 ms |
2648 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
5 ms |
2908 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
2 ms |
2652 KB |
Output is correct |
47 |
Correct |
4 ms |
2908 KB |
Output is correct |
48 |
Correct |
2 ms |
2652 KB |
Output is correct |
49 |
Correct |
4 ms |
2908 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
9 ms |
3092 KB |
Output is correct |
52 |
Correct |
2 ms |
2652 KB |
Output is correct |
53 |
Correct |
13 ms |
2908 KB |
Output is correct |
54 |
Correct |
12 ms |
2908 KB |
Output is correct |
55 |
Correct |
2 ms |
2652 KB |
Output is correct |
56 |
Correct |
2 ms |
2652 KB |
Output is correct |
57 |
Correct |
1 ms |
2652 KB |
Output is correct |
58 |
Correct |
13 ms |
3108 KB |
Output is correct |
59 |
Correct |
2 ms |
2652 KB |
Output is correct |
60 |
Correct |
2 ms |
2652 KB |
Output is correct |
61 |
Correct |
2 ms |
2652 KB |
Output is correct |
62 |
Correct |
2 ms |
2652 KB |
Output is correct |
63 |
Correct |
4 ms |
2944 KB |
Output is correct |
64 |
Correct |
4 ms |
2908 KB |
Output is correct |
65 |
Correct |
2 ms |
2652 KB |
Output is correct |
66 |
Correct |
2 ms |
2648 KB |
Output is correct |
67 |
Correct |
7 ms |
2908 KB |
Output is correct |
68 |
Correct |
4 ms |
2904 KB |
Output is correct |
69 |
Correct |
2 ms |
2652 KB |
Output is correct |
70 |
Correct |
4 ms |
2908 KB |
Output is correct |
71 |
Correct |
5 ms |
2908 KB |
Output is correct |
72 |
Correct |
5 ms |
2908 KB |
Output is correct |
73 |
Correct |
2 ms |
2652 KB |
Output is correct |
74 |
Correct |
4 ms |
2908 KB |
Output is correct |
75 |
Correct |
5 ms |
2908 KB |
Output is correct |
76 |
Correct |
3 ms |
2652 KB |
Output is correct |
77 |
Correct |
7 ms |
2908 KB |
Output is correct |
78 |
Correct |
1 ms |
2652 KB |
Output is correct |
79 |
Correct |
3 ms |
2652 KB |
Output is correct |
80 |
Correct |
3 ms |
2648 KB |
Output is correct |
81 |
Correct |
7 ms |
2908 KB |
Output is correct |
82 |
Correct |
1 ms |
2652 KB |
Output is correct |
83 |
Correct |
3 ms |
2652 KB |
Output is correct |
84 |
Correct |
5 ms |
2908 KB |
Output is correct |
85 |
Correct |
1 ms |
2652 KB |
Output is correct |
86 |
Correct |
5 ms |
2940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
0 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2636 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2716 KB |
Output is correct |
28 |
Correct |
2 ms |
2740 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2768 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
2 ms |
2648 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
29 ms |
4864 KB |
Output is correct |
46 |
Correct |
17 ms |
4700 KB |
Output is correct |
47 |
Correct |
30 ms |
4956 KB |
Output is correct |
48 |
Correct |
29 ms |
4948 KB |
Output is correct |
49 |
Correct |
16 ms |
4700 KB |
Output is correct |
50 |
Correct |
46 ms |
5384 KB |
Output is correct |
51 |
Correct |
32 ms |
4800 KB |
Output is correct |
52 |
Correct |
17 ms |
4696 KB |
Output is correct |
53 |
Correct |
15 ms |
4700 KB |
Output is correct |
54 |
Correct |
3 ms |
2908 KB |
Output is correct |
55 |
Correct |
45 ms |
5332 KB |
Output is correct |
56 |
Correct |
9 ms |
4440 KB |
Output is correct |
57 |
Correct |
13 ms |
4712 KB |
Output is correct |
58 |
Correct |
16 ms |
4444 KB |
Output is correct |
59 |
Correct |
8 ms |
4440 KB |
Output is correct |
60 |
Correct |
8 ms |
4440 KB |
Output is correct |
61 |
Correct |
16 ms |
4440 KB |
Output is correct |
62 |
Correct |
11 ms |
4444 KB |
Output is correct |
63 |
Correct |
20 ms |
4636 KB |
Output is correct |
64 |
Correct |
8 ms |
4444 KB |
Output is correct |
65 |
Correct |
26 ms |
4732 KB |
Output is correct |
66 |
Correct |
12 ms |
4444 KB |
Output is correct |
67 |
Correct |
23 ms |
4572 KB |
Output is correct |
68 |
Correct |
23 ms |
4700 KB |
Output is correct |
69 |
Correct |
24 ms |
4700 KB |
Output is correct |
70 |
Correct |
12 ms |
4440 KB |
Output is correct |
71 |
Correct |
23 ms |
4700 KB |
Output is correct |
72 |
Correct |
21 ms |
4700 KB |
Output is correct |
73 |
Correct |
28 ms |
4700 KB |
Output is correct |
74 |
Correct |
11 ms |
4444 KB |
Output is correct |
75 |
Correct |
10 ms |
3576 KB |
Output is correct |
76 |
Correct |
20 ms |
4700 KB |
Output is correct |
77 |
Correct |
27 ms |
4700 KB |
Output is correct |
78 |
Correct |
13 ms |
3676 KB |
Output is correct |
79 |
Correct |
11 ms |
3416 KB |
Output is correct |
80 |
Correct |
5 ms |
3160 KB |
Output is correct |
81 |
Correct |
13 ms |
3676 KB |
Output is correct |
82 |
Correct |
19 ms |
4532 KB |
Output is correct |
83 |
Correct |
5 ms |
3164 KB |
Output is correct |
84 |
Correct |
19 ms |
4444 KB |
Output is correct |