题目:
Two undirected simple graphs G1=⟨V,E1⟩ and G2=⟨V,E2⟩ where V={1,2,…,n} are isomorphic when there exists a bijection ϕ on V satisfying {ϕ(x),ϕ(y)}∈E1 if and only if {x, y} ∈ E2.Given two graphs G1=⟨V,E1⟩ and G2=⟨V,E2⟩, count the number of graphs G=⟨V,E⟩ satisfying the following condition:
- E⊆E2.
- G1 and G are isomorphic.
- 1 ≤ n ≤ 8
大意: 求一个图通过映射,在另一个图有多少种同构情况
思路: 因为最多只有八个点,所以用next_permutation搜索各种映射情况
需要注意的是不同种的映射有可能是同一种情况,所以要注意去重
去重的方法有,一种就是就哈希,用set把每一种同构情况存储下来
另一种就是我们可以遍历到各种所有映射情况,求出一种同构体会被算重复多少次,最后的次数/重复次数就是所得
哈希,注意给边编号
#include<bits/stdc++.h>
using namespace std;
int a[10];
int mp1[10][10],mp2[10][10];
set<int>vis;
int main()
{
int n,m1,m2;
while(~scanf("%d%d%d",&n,&m1,&m2))
{
memset(mp1,0,sizeof mp1);
memset(mp2,0,sizeof mp2);
vis.clear();
for(int i=1;i<=m1;i++)
{
int u,v;
scanf("%d%d",&u,&v);
mp1[u][v]=mp1[v][u]