Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n, m, k, vis[35], cnt[15], best = 2e9;
  4. vector <int> te[35], br[35];
  5. void Try(int curs, int curm)
  6. {
  7.     if (curs > n)
  8.     {
  9.         best = min(best, curm);
  10.         return;
  11.     }
  12.     if (curm > best) return;
  13.     for (int i : te[curs])
  14.     {
  15.         bool ok = true;
  16.         for (int j : br[curs])
  17.         {
  18.             if (vis[j] == i)
  19.             {
  20.                 ok = false;
  21.                 break;
  22.             }
  23.         }
  24.         if (ok)
  25.         {
  26.             vis[curs] = i;
  27.             cnt[i]++;
  28.             Try(curs + 1, max(curm, cnt[i]));
  29.             cnt[i]--;
  30.             vis[curs] = 0;
  31.         }
  32.     }
  33. }
  34. int main()
  35. {
  36.     ios::sync_with_stdio(0);
  37.     cin.tie(0);
  38.     if (fopen("input.txt", "r"))
  39.         assert(freopen("input.txt", "r", stdin));
  40.     cin >> m >> n;
  41.     for (int i = 1; i <= m; ++i)
  42.     {
  43.         int x; cin >> x;
  44.         while (x--)
  45.         {
  46.             int u; cin >> u;
  47.             te[u].push_back(i);
  48.         }
  49.     }
  50.     cin >> k;
  51.     for (int i = 1; i <= k; ++i)
  52.     {
  53.         int u, v;
  54.         cin >> u >> v;
  55.         br[u].push_back(v);
  56.         br[v].push_back(u);
  57.     }
  58.     Try(1, 0);
  59.     if (best == 2e9) best = -1;
  60.     cout << best;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement