1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <bits/stdc++.h> using namespace std; int n, m1, m2, res, pre[10], mp1[10][10], mp2[10][10]; map<long long, int> p; int main() { while (~scanf("%d%d%d", &n, &m1, &m2)) { memset(mp1, 0, sizeof(mp1)); memset(mp2, 0, sizeof(mp2)); p.clear(); res = 0; for (int i = 1; i <= m1; i++) { int x, y; scanf("%d%d", &x, &y); mp1[x][y] = mp1[y][x] = 1; } for (int i = 1; i <= m2; i++) { int x, y; scanf("%d%d", &x, &y); mp2[x][y] = mp2[y][x] = i; } for (int i = 1; i <= n; i++) pre[i] = i; do { int flag = 1; long long now = 0; for (int i = 1; i <= n && flag; i++) { for (int j = 1; j <= n && flag; j++) { if (mp1[i][j] == 1) { if (!mp2[pre[i]][pre[j]]) flag = 0; now |= 1LL << (mp2[pre[i]][pre[j]]); } } } if (flag && p[now] == 0) { res++; p[now] = 1; } } while (next_permutation(pre + 1, pre + n + 1)); printf("%d\n", res); } return 0; }
|