#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){
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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
1 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 |
0 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2884 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2740 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 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 |
2904 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2936 KB |
Output is correct |
26 |
Correct |
2 ms |
2908 KB |
Output is correct |
27 |
Correct |
2 ms |
2908 KB |
Output is correct |
28 |
Correct |
2 ms |
2740 KB |
Output is correct |
29 |
Correct |
2 ms |
2904 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2816 KB |
Output is correct |
32 |
Correct |
2 ms |
2736 KB |
Output is correct |
33 |
Correct |
2 ms |
2908 KB |
Output is correct |
34 |
Correct |
2 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 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 |
2908 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2908 KB |
Output is correct |
43 |
Correct |
3 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
49 ms |
5332 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
53 ms |
8272 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
48 ms |
8028 KB |
Output is correct |
16 |
Correct |
51 ms |
7844 KB |
Output is correct |
17 |
Correct |
50 ms |
7864 KB |
Output is correct |
18 |
Correct |
53 ms |
8020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
1 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 |
0 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2884 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2740 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 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 |
2904 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2936 KB |
Output is correct |
26 |
Correct |
2 ms |
2908 KB |
Output is correct |
27 |
Correct |
2 ms |
2908 KB |
Output is correct |
28 |
Correct |
2 ms |
2740 KB |
Output is correct |
29 |
Correct |
2 ms |
2904 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2816 KB |
Output is correct |
32 |
Correct |
2 ms |
2736 KB |
Output is correct |
33 |
Correct |
2 ms |
2908 KB |
Output is correct |
34 |
Correct |
2 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 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 |
2908 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2908 KB |
Output is correct |
43 |
Correct |
3 ms |
2908 KB |
Output is correct |
44 |
Correct |
5 ms |
2908 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2904 KB |
Output is correct |
47 |
Correct |
4 ms |
2908 KB |
Output is correct |
48 |
Correct |
3 ms |
2908 KB |
Output is correct |
49 |
Correct |
4 ms |
2972 KB |
Output is correct |
50 |
Correct |
5 ms |
2908 KB |
Output is correct |
51 |
Correct |
10 ms |
3420 KB |
Output is correct |
52 |
Correct |
2 ms |
2908 KB |
Output is correct |
53 |
Correct |
14 ms |
3540 KB |
Output is correct |
54 |
Correct |
13 ms |
3400 KB |
Output is correct |
55 |
Correct |
2 ms |
2904 KB |
Output is correct |
56 |
Correct |
2 ms |
2908 KB |
Output is correct |
57 |
Correct |
1 ms |
2652 KB |
Output is correct |
58 |
Correct |
13 ms |
3480 KB |
Output is correct |
59 |
Correct |
2 ms |
2904 KB |
Output is correct |
60 |
Correct |
2 ms |
2908 KB |
Output is correct |
61 |
Correct |
3 ms |
2908 KB |
Output is correct |
62 |
Correct |
3 ms |
2908 KB |
Output is correct |
63 |
Correct |
5 ms |
2908 KB |
Output is correct |
64 |
Correct |
4 ms |
2904 KB |
Output is correct |
65 |
Correct |
2 ms |
2908 KB |
Output is correct |
66 |
Correct |
3 ms |
2812 KB |
Output is correct |
67 |
Correct |
6 ms |
3012 KB |
Output is correct |
68 |
Correct |
4 ms |
2904 KB |
Output is correct |
69 |
Correct |
2 ms |
2908 KB |
Output is correct |
70 |
Correct |
4 ms |
3024 KB |
Output is correct |
71 |
Correct |
6 ms |
3160 KB |
Output is correct |
72 |
Correct |
5 ms |
3164 KB |
Output is correct |
73 |
Correct |
2 ms |
2908 KB |
Output is correct |
74 |
Correct |
4 ms |
2908 KB |
Output is correct |
75 |
Correct |
5 ms |
3164 KB |
Output is correct |
76 |
Correct |
4 ms |
2908 KB |
Output is correct |
77 |
Correct |
7 ms |
3276 KB |
Output is correct |
78 |
Correct |
2 ms |
2908 KB |
Output is correct |
79 |
Correct |
5 ms |
2908 KB |
Output is correct |
80 |
Correct |
3 ms |
2908 KB |
Output is correct |
81 |
Correct |
7 ms |
3164 KB |
Output is correct |
82 |
Correct |
1 ms |
2652 KB |
Output is correct |
83 |
Correct |
4 ms |
2908 KB |
Output is correct |
84 |
Correct |
6 ms |
3164 KB |
Output is correct |
85 |
Correct |
1 ms |
2652 KB |
Output is correct |
86 |
Correct |
5 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
1 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 |
0 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2884 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
2 ms |
2740 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
2 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 |
2904 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2936 KB |
Output is correct |
26 |
Correct |
2 ms |
2908 KB |
Output is correct |
27 |
Correct |
2 ms |
2908 KB |
Output is correct |
28 |
Correct |
2 ms |
2740 KB |
Output is correct |
29 |
Correct |
2 ms |
2904 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2816 KB |
Output is correct |
32 |
Correct |
2 ms |
2736 KB |
Output is correct |
33 |
Correct |
2 ms |
2908 KB |
Output is correct |
34 |
Correct |
2 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 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 |
2908 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2908 KB |
Output is correct |
43 |
Correct |
3 ms |
2908 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
31 ms |
6672 KB |
Output is correct |
46 |
Correct |
18 ms |
5464 KB |
Output is correct |
47 |
Correct |
30 ms |
6736 KB |
Output is correct |
48 |
Correct |
30 ms |
6668 KB |
Output is correct |
49 |
Correct |
16 ms |
5468 KB |
Output is correct |
50 |
Correct |
50 ms |
7632 KB |
Output is correct |
51 |
Correct |
31 ms |
6744 KB |
Output is correct |
52 |
Correct |
14 ms |
5464 KB |
Output is correct |
53 |
Correct |
15 ms |
5468 KB |
Output is correct |
54 |
Correct |
3 ms |
3040 KB |
Output is correct |
55 |
Correct |
47 ms |
7636 KB |
Output is correct |
56 |
Correct |
9 ms |
4952 KB |
Output is correct |
57 |
Correct |
13 ms |
5344 KB |
Output is correct |
58 |
Correct |
18 ms |
5412 KB |
Output is correct |
59 |
Correct |
8 ms |
4956 KB |
Output is correct |
60 |
Correct |
8 ms |
4900 KB |
Output is correct |
61 |
Correct |
19 ms |
5468 KB |
Output is correct |
62 |
Correct |
12 ms |
5212 KB |
Output is correct |
63 |
Correct |
21 ms |
5720 KB |
Output is correct |
64 |
Correct |
8 ms |
4952 KB |
Output is correct |
65 |
Correct |
25 ms |
5980 KB |
Output is correct |
66 |
Correct |
12 ms |
5204 KB |
Output is correct |
67 |
Correct |
20 ms |
5724 KB |
Output is correct |
68 |
Correct |
25 ms |
5996 KB |
Output is correct |
69 |
Correct |
25 ms |
5976 KB |
Output is correct |
70 |
Correct |
12 ms |
5212 KB |
Output is correct |
71 |
Correct |
23 ms |
5960 KB |
Output is correct |
72 |
Correct |
21 ms |
5652 KB |
Output is correct |
73 |
Correct |
27 ms |
6236 KB |
Output is correct |
74 |
Correct |
11 ms |
5212 KB |
Output is correct |
75 |
Correct |
12 ms |
4188 KB |
Output is correct |
76 |
Correct |
21 ms |
5724 KB |
Output is correct |
77 |
Correct |
28 ms |
6264 KB |
Output is correct |
78 |
Correct |
14 ms |
4444 KB |
Output is correct |
79 |
Correct |
11 ms |
4184 KB |
Output is correct |
80 |
Correct |
6 ms |
3416 KB |
Output is correct |
81 |
Correct |
14 ms |
4440 KB |
Output is correct |
82 |
Correct |
20 ms |
5720 KB |
Output is correct |
83 |
Correct |
6 ms |
3420 KB |
Output is correct |
84 |
Correct |
20 ms |
5720 KB |
Output is correct |