链接: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. 接口测试时遇到 java 代码加密请求数据,用 python 的我该怎么办?

    前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公司的产品都是java语言实现的.所以加密处理也是java实 ...

  2. MySQL中一些关于索引的知识点

    什么是索引 索引是一种数据结构,其作用就是用来提高数据查询效率.比较常用的比喻就是将其类比为书籍的目录.通过目录可以精确的找到某一章节的内容所在页. 在数据量较小的时候使用索引其实也没有什么意义,即使 ...

  3. Python实现批量处理扫描特定目录

    ## 简述在渗透测试中遇到相同CMS站点时,搞定一个站点,相当于拿了一个站群的通用漏洞,所以我们首先需要标注站点的CMS类型,根据要求编写如下脚本 ## 要求1.访问特定目录,如:站点特定 /cmsa ...

  4. 关于HostnameVerifier接口的解读

    在项目中我们需要调用https接口请求.我们使用httpClient,构建HttpClient对象时涉及到使用HostnameVerifier接口实例. HostnameVerifier接口定义如下: ...

  5. Java线程池的增长过程

    通过ThreadPoolExecutor的方式创建线程池 ThreadPoolExecutor 构造方法: public ThreadPoolExecutor(int corePoolSize, in ...

  6. 单元测试python unittest

    记录自己学习单元测试框架的一篇博客 菜鸟的学习之路比较艰辛到处找资料一把辛酸泪啊 1.首先是创建一个类里面设计一些简单的函数方便写用例: 原谅我蹩脚的英文直接用拼音命名了 : 2.接着就是创建用例文件 ...

  7. Mysql 分页order by一个相同字段,发现顺序错乱

    两次分页查询,其中跳过了2个id   select * from jdp_tb_trade  where jdp_modified>='2017-04-24 20:22:01' and jdp_ ...

  8. 【0726 | Day 2】编程语言分类/主流编程语言介绍/网络的瓶颈效应

    编程语言分类 机器语言 与硬件交互 优点:执行效率高 缺点:开发效率低 汇编语言 间接与硬件交互 优点(相较于机器语言):开发效率高 缺点(相较于机器语言):执行效率低 高级语言 简单化指令,让人人都 ...

  9. Mac如何前往文件夹 修改hosts文件 显示隐藏文件 Mac如何查看剪切板

    Mac 如何前往文件夹 首先,回到桌面,或者点击Finder(访达) 然后输入快捷键 ⌘ Command + ⇧ Shift + G 或者在Finder上方状态栏中点击‘前往’>>> ...

  10. 谷歌hack

    0x00 网上搜集整理的一些可能会用到的Googlehack语法 0x01 intitle: 从网页标题中搜索指定的关键字,可专门用来搜索指定版本名称的各类 web 程序,也可用 allintitle ...