链接: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, m

1

 and 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

 and b

i

 which denote {a

i

, b

i

} ∈ E

1

.
The i-th of the last m

2

 lines contains 2 integers a

i

 and b

i

 which denote {a

i

, b

i

} ∈ E

2

.

输出描述:

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

输入例子:
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

输入

复制

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 ≤ a

i

, b

i

 ≤ n
* The number of test cases does not exceed 50. 求图G1有多少个子图和图G2是同构图
枚举图G1的全排列子图,然后判断每一个子图是否和图G2是同构图
判断原理:
同构要求边,点以及点的结构都相同。
我们先存好图G1中每种边点结构的关系,用一个vis数组存下每条边
然后在全排列判断每个子图的时候判断这个子图是否和图G2同构,同构就用个set保存下这种情况(每种情况用散列哈希求出一个独一无二的值)
最后set的size就是结果
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e1;
const int mod = 1e9 + 7;
typedef long long ll;
ll vis[maxn][maxn], f[maxn];
pair<ll,ll> p[maxn*10];
int main() {
ll n, m1, m2;
while( cin >> n >> m1 >> m2 ) {
memset( vis, 0, sizeof(vis) );
for( ll i = 1; i <= n; i ++ ) {
f[i] = i;
}
for( ll i = 1, a, b; i <= m1; i ++ ) {
cin >> a >> b;
vis[a][b] = vis[b][a] = 1;
}
for( ll i = 1; i <= m2; i ++ ) {
cin >> p[i].first >> p[i].second;
}
set<ll> s;
do{
ll ha = 0, cnt = 0;
for( ll i = 1; i <= m2; i ++ ) {
if( vis[f[p[i].first]][f[p[i].second]] ) { //判断边点结构
ha = ha*133 + i; //散列求点,确保每种情况得到的点不一样
ha %= mod;
cnt ++; //判断边
}
}
if( cnt == m1 ) {
s.insert(ha);
}
} while( next_permutation(f+1,f+n+1) ); //全排列图G1
cout << s.size() << endl;
}
return 0;
}

  

Two Graphs 牛客网暑期ACM多校训练营(第一场)D 图论基础知识 全排列的更多相关文章

  1. 牛客网暑期ACM多校训练营 第九场

    HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a ...

  2. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  3. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  4. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  5. 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学

    牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...

  6. 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)

    牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...

  7. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  8. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  9. 牛客网暑期ACM多校训练营(第七场)Bit Compression

    链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...

随机推荐

  1. ubuntu 下常用的mysql 命令

    一.mysql服务操作  0.查看数据库版本 sql-> status;  1.net start mysql //启动mysql服务  2.net stop mysql //停止mysql服务 ...

  2. postman使用pre-request script计算md5

    接口加了验签逻辑,具体是md5(salt+时间戳).被某君吐槽说测试不方便啊能不能先关掉.其实没有必要打开又关闭验签功能,postman的pre-request script功能完全可以模拟客户端加密 ...

  3. Is it a full physical image???

    My friend asked me why she could not find some important files in a physical image acquired from an ...

  4. str_replace导致的注入问题汇总

    研究了下replace的注入安全问题. 一般sql注入的过滤方式就是引用addslashes函数进行过滤. 他会把注入的单引号转换成\',把双引号转换成\",反斜杠会转换成\\等 写一段ph ...

  5. 理解分布式一致性与Raft算法

    理解分布式一致性与Raft算法 永远绕不开的CAP定理 出于可用性及负载方面考虑,一个分布式系统中数据必然不会只存在于一台机器,一致性简单地说就是分布式系统中的各个部分保持数据一致 但让数据保持一致往 ...

  6. python使用pip安装第三方库以及镜像使用豆瓣源安装第三方库

    2018/8/7  在使用pip安装pynum第三方库时的随笔 所有的前提都是你成功安装了pip 首先第一步 打开命令提示符  输入pip show pip 查看当前pip版本 然后可以上官网搜索一下 ...

  7. 算法与数据结构基础 - 二叉查找树(Binary Search Tree)

    二叉查找树基础 二叉查找树(BST)满足这样的性质,或是一颗空树:或左子树节点值小于根节点值.右子树节点值大于根节点值,左右子树也分别满足这个性质. 利用这个性质,可以迭代(iterative)或递归 ...

  8. Web前端开发工程师课程大纲

    PHP程序员雷雪松整理出来的一套独一无二的Web前端开发课程.本套Web前端开发课程专门为想励志成为优秀web前端工程师的学习者而总结归纳的,本套Web前端课程舍弃了一些不常用的即将废弃的HTML标签 ...

  9. JSmooth 将java代码打包成exe

    JSmooth 将java代码打包成exe 前言 java代码写了这么多了,但由于jdk的限制,我只能在jdk电脑上运行项目.所以最近在研究打包exe这个问题,今天终于实现了. JSmooth下载 前 ...

  10. JVM类生命周期概述:加载时机与加载过程

    一个.java文件在编译后会形成相应的一个或多个Class文件,这些Class文件中描述了类的各种信息,并且它们最终都需要被加载到虚拟机中才能被运行和使用.事实上,虚拟机把描述类的数据从Class文件 ...