Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector < vector < long long > > au;
  4. long long t, n, m, x, y, a, b;
  5. vector <long long> dp;
  6. vector <bool> mer;
  7.  
  8. int main()
  9. {
  10.     freopen ("stdc.in", "r", stdin);
  11.     freopen ("stdc.out", "w", stdout);
  12.  
  13.     cin >> t;
  14.     for (int i = 1; i <= t; i++)
  15.     {
  16.         long long mx = 0, ans = 0;
  17.         vector <long long> ansv;
  18.         au.clear();
  19.         mer.clear();
  20.         cin >> n >> m;
  21.         au.resize(m+1);              
  22.         mer.resize(n+1);
  23.         for (int j = 0; j < m; j++)
  24.         {
  25.             cin >> x;
  26.             for (int z = 1; z <= x; z++)
  27.             {
  28.                 cin >> y;
  29.                 au[j].push_back(y);
  30.             }
  31.         }
  32.         for (int mask = 0; mask < (1 << m); mask++)
  33.         {
  34.             cout << "m " << mask << endl;
  35.             mer.clear();
  36.             b = 0;
  37.             for (int v = 0; v < m; v++)
  38.             {
  39.                 a = 0;
  40.                 if (((mask >> v) & 1) == 1)
  41.                 {
  42.                     for (int z = 0; z < (int)au[v].size(); z++)
  43.                     {
  44.                         if (mer[au[v][z]] == 0)
  45.                         {
  46.                             mer[au[v][z]] = 1;
  47.                         }
  48.                         else
  49.                         {
  50.                             a = 1;
  51.                             break;
  52.                         }
  53.                     }
  54.                     if (a == 1)
  55.                         break;
  56.                     b++;
  57.                 }
  58.             }
  59.             if (a != 1 && b > mx)
  60.             {
  61.                 mx = b;
  62.                 ans = mask;
  63.     /*          for (int j = 1; j <= n; j++)
  64.                     cout << mer[j] << ' ';
  65.                 cout << endl;*/
  66.             }
  67.         }
  68.         cout << mx << ' ' << ans << ' ' << endl;
  69.         long long d = 1;
  70.         while (ans != 0)
  71.         {
  72.             if (ans % 2 == 1)
  73.             {
  74.                 cout << d << ' ';  
  75.             }
  76.             ans = ans / 2;
  77.             d++;
  78.         }
  79.         cout << endl;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement