-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequenceLand.cpp
More file actions
81 lines (62 loc) · 1.43 KB
/
sequenceLand.cpp
File metadata and controls
81 lines (62 loc) · 1.43 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N = 304;
vector<bool> visited;
vector<vector<int>> adjList;
int ans = 0;
void dfs (int node)
{
visited[node] = true;
ans++;
for(auto i: adjList[node]) {
if (visited[i] == false) {
dfs(i);
}
}
}
int main ()
{
int n, K;
cin >> n >> K;
adjList.resize(n);
visited.resize(n, false);
vector<int> ids [n];
for (int i = 0; i < n; ++i) {
int len;
cin >> len;
vector<int> curr;
for (int k = 0; k < len; ++k) {
int yes;
cin >> yes;
curr.push_back(yes);
}
sort(curr.begin(), curr.end());
ids[i] = curr;
}
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
int ind1 = 0;
int ind2 = 0;
int com = 0;
while (ind1 < ids[i].size() && ind2 < ids[j].size()) {
if (ids[i][ind1] == ids[j][ind2]) {
com++;
ind1++;
ind2++;
} else if (ids[i][ind1] > ids[j][ind2]) {
ind2++;
} else {
ind1 ++;
}
}
if (com >= K) {
adjList[i].push_back(j);
adjList[j].push_back(i);
}
}
}
dfs(0);
cout << ans << endl;
}