Problem10993--Two Graphs

10993: Two Graphs

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Two undirected simple graphs $G_1 =⟨V,E_1⟩$ and $G_2 =⟨V,E_2⟩$ where $V={1,2,…,n}$ are isomorphic when there exists a bijection $ϕ$ on $V$ satisfying $\{ϕ(x),ϕ(y)\}\in E_1$ if and only if $\{x, y\} \in E_2$. 
Given two graphs $G_1 =⟨V,E_1⟩$ and $G_2 =⟨V,E_2⟩$, count the number of graphs $G=⟨V,E⟩$ satisfying the following condition: 
* $E⊆E_2$. 
* $G_1$ and $G$ are isomorphic.

Input

The input consists of several test cases and is terminated by end-of-file. 
The first line of each test case contains three integers $n, m_1, m_2$ where $|E_1| = m_1$ and $|E_2| = m_2$. 
The $i$-th of the following $m_1$ lines contains $2$ integers $a_i,b_i$ which denote $\{a_i, b_i\} \in E_1$. 
The $i$-th of the last $m_2$ lines contains $2$ integers $a_i, b_i$ which denote $\{a_i, b_i\} \in E_2$.

Output

For each test case, print an integer which denotes the result.

Constraints

$1 ≤ n ≤ 8$
$1≤m_1 ≤m_ 2 ≤ \frac{n(n−1)}{2}$
$1 ≤ a_i, b_i ≤ n$
The number of test cases does not exceed $50$.

Sample 1 Input

3 1 2
1 3
1 2
2 3
4 2 3
1 2
1 3
4 1
4 2
4 3

Sample 1 Output

2
3

HINT

牛客网

Source/Category

哈希