-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence_land.cpp
More file actions
60 lines (58 loc) · 1.05 KB
/
sequence_land.cpp
File metadata and controls
60 lines (58 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
int n,k,num=0,M=0,checked[310];
vector<int> adj[310],arr[310];
void display(vector<int> a)
{
for(int i=0;i<a.size();i++)
cout<<a[i]<<" ";
}
bool compare(vector<int> a,vector<int> b)
{
int cal=0;
for(int i=0;i<a.size();i++)
for(int j=0;j<b.size();j++)
if(a[i]==b[j])
cal++;
if(cal>=k)
return true;
return false;
}
void dfs(int i)
{
//cout<<"checking "<<i<<endl;
if(!checked[i])
{
checked[i]=1;
++num;
for(int a=0;a<adj[i].size();a++)
dfs(adj[i][a]);
}
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
int n1;cin>>n1;
arr[i].resize(n1);
for(int j=0;j<n1;j++)
cin>>arr[i][j];
for(int l=1;l<i;l++)
if(compare(arr[i],arr[l]))
{
//cout<<"match of "<<i<<" found with "<<l<<endl;
adj[i].push_back(l);
adj[l].push_back(i);
}
}
for(int i=1;i<=n;i++)
{
if(!checked[i])
dfs(i);
M=max(M,num);
num=0;
}
cout<<M<<endl;
//cout<<"*****"<<adj[1].size();
}