同构——(思维+爆搜)

链接:https://www.nowcoder.com/acm/contest/139/D
来源:牛客网
 

Two undirected simple graphs and where are isomorphic when there exists a bijection on V satisfying  if and only if {x, y} ∈ E2.
Given two graphs and , count the number of graphs satisfying the following condition:
* .
* G1 and G are isomorphic.

输入描述:

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, m1 and m2 where |E1| = m1 and |E2| = m2.
The i-th of the following m1 lines contains 2 integers ai and bi which denote {ai, bi} ∈ E1.
The i-th of the last m2 lines contains 2 integers ai and bi which denote {ai, bi} ∈ E2.

输出描述:

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

示例1

输入

复制

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

输出

复制

2
3

备注:

* 1 ≤ n ≤ 8
* 
* 1 ≤ ai, bi ≤ n
* The number of test cases does not exceed 50.

 

思路:若想同构,就要找出一一对应的点来。对于E1中的所有的点和所有的边,一定要有E1中的点点所连的边在E2中都有。仔细看下面代码中最后的判断。这份代码可以说是十分暴力了。

代码:

#include
using namespace std;

int n,m1,m2,a,b;
int vis[10][10],pre[10],w[10],ans;
mapmm;

struct AA
{
    int x,y;
}pos[50];

int dfs(int rt)///枚举所有的点
{
    if(rt==n+1)
    {
        long long pp=0;
        for(int i=1;i<=m1;i++)
        {
            if(vis[pre[pos[i].x]][pre[pos[i].y]]==0)
                return 0;
            pp|=1<

 

你可能感兴趣的:(图论,DFS)