Guest User

INOI1302

a guest
Jun 22nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ull unsigned long long
  5. vector < set <ull> > arr;
  6.  
  7. int main()
  8. {
  9.     std::ios::sync_with_stdio(false);
  10.     int n, k;
  11.     cin >> n >> k;
  12.     arr = vector <set <ull> >(n);
  13.     vector < bool > chosen(n, 0);
  14.     chosen[0] = 1;
  15.  
  16.     for(int i = 0; i < n; i++)
  17.     {
  18.         int p;
  19.         cin >> p;
  20.         for(int j = 0; j < p; j++)
  21.         {
  22.             ull num;
  23.             cin >> num;
  24.             arr[i].insert(num);
  25.         }
  26.     }
  27.  
  28.     ull rel = 1;
  29.     for(int i = 0; i < n; i++)
  30.     {
  31.         for(int j = i + 1; j < n; j++)
  32.         {
  33.             ull match = 0;
  34.             set <ull>::iterator s1, s2;
  35.             s1 = arr[i].begin();
  36.             s2 = arr[j].begin();
  37.             if((chosen[i] == 1 && chosen[j] == 0) || (chosen[i] == 0 && chosen[j] == 1))
  38.             {
  39.                 //cout << i << " -- " << j << endl;
  40.                 while((s1 != arr[i].end()) && (s2 != arr[j].end()))
  41.                 {
  42.                     //cout << *s1 << " " << *s2 << endl;
  43.                     if((*s1) == (*s2))
  44.                     {
  45.                         ++match;
  46.                         ++s1;
  47.                         ++s2;
  48.                         //cout << match << endl;
  49.                     }
  50.                     else if((*s1) < (*s2))
  51.                         ++s1;
  52.                     else
  53.                         ++s2;
  54.                 }
  55.                 if(match >= k)
  56.                 {
  57.                     rel++;
  58.                     chosen[i] = 1;
  59.                     chosen[j] = 1;
  60.                     //cout << rel << endl;
  61.                 }
  62.             }
  63.         }
  64.     }
  65.     cout << rel << endl;
  66.     return 0;
  67. }
Add Comment
Please, Sign In to add comment