Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ull unsigned long long
- vector < set <ull> > arr;
- int main()
- {
- std::ios::sync_with_stdio(false);
- int n, k;
- cin >> n >> k;
- arr = vector <set <ull> >(n);
- vector < bool > chosen(n, 0);
- chosen[0] = 1;
- for(int i = 0; i < n; i++)
- {
- int p;
- cin >> p;
- for(int j = 0; j < p; j++)
- {
- ull num;
- cin >> num;
- arr[i].insert(num);
- }
- }
- ull rel = 1;
- for(int i = 0; i < n; i++)
- {
- for(int j = i + 1; j < n; j++)
- {
- ull match = 0;
- set <ull>::iterator s1, s2;
- s1 = arr[i].begin();
- s2 = arr[j].begin();
- if((chosen[i] == 1 && chosen[j] == 0) || (chosen[i] == 0 && chosen[j] == 1))
- {
- //cout << i << " -- " << j << endl;
- while((s1 != arr[i].end()) && (s2 != arr[j].end()))
- {
- //cout << *s1 << " " << *s2 << endl;
- if((*s1) == (*s2))
- {
- ++match;
- ++s1;
- ++s2;
- //cout << match << endl;
- }
- else if((*s1) < (*s2))
- ++s1;
- else
- ++s2;
- }
- if(match >= k)
- {
- rel++;
- chosen[i] = 1;
- chosen[j] = 1;
- //cout << rel << endl;
- }
- }
- }
- }
- cout << rel << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment