牛客多校第一场 D Two Graphs(判断图同构)

链接: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.

题目大意:有两个图G_{_{1}}<V,E_{1}>,G_{_{2}}<V,E_{2}>,要求出满足如下条件的G<V,E>的个数:

1、E\subseteq E_{2}

2、图G与图G1同构

题目思路:由于图中只有8个点,所以我们可以考虑枚举G2的所有的图的情况,再用邻接矩阵来进行判断两个图是否同构,最后还需要减掉G1与G1同构的情况,就是得到最终答案。

#include 
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pb push_back
#define MP make_pair
#define FIN freopen("in.txt","r",stdin)
#define fuck(x) cout<<"["<pii;
const int mod=1e9+7;

int n,m1,m2;
int a[10];
int mp1[10][10],mp2[10][10];

int main(){
    while(~scanf("%d%d%d",&n,&m1,&m2)){
        memset(mp1,0,sizeof(mp1));
        memset(mp2,0,sizeof(mp2));
        for(int i=1;i<=n;i++) a[i]=i;
        int ans=0,res=0;
        for(int i=0;i

 

你可能感兴趣的:(ACM)