Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n, m, k, vis[35], cnt[15], best = 2e9;
- vector <int> te[35], br[35];
- void Try(int curs, int curm)
- {
- if (curs > n)
- {
- best = min(best, curm);
- return;
- }
- if (curm > best) return;
- for (int i : te[curs])
- {
- bool ok = true;
- for (int j : br[curs])
- {
- if (vis[j] == i)
- {
- ok = false;
- break;
- }
- }
- if (ok)
- {
- vis[curs] = i;
- cnt[i]++;
- Try(curs + 1, max(curm, cnt[i]));
- cnt[i]--;
- vis[curs] = 0;
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- if (fopen("input.txt", "r"))
- assert(freopen("input.txt", "r", stdin));
- cin >> m >> n;
- for (int i = 1; i <= m; ++i)
- {
- int x; cin >> x;
- while (x--)
- {
- int u; cin >> u;
- te[u].push_back(i);
- }
- }
- cin >> k;
- for (int i = 1; i <= k; ++i)
- {
- int u, v;
- cin >> u >> v;
- br[u].push_back(v);
- br[v].push_back(u);
- }
- Try(1, 0);
- if (best == 2e9) best = -1;
- cout << best;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement