链接: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. codeforces 371 C-Hamburgers

    一个乱七八糟的故事背景,可以练练英语阅读. 大概的意思是Polycarpus喜欢汉堡,现在他有你ns片香肠片,nb面包,nc块起司,有r卢布,每种东西都有价格,如果不够他可以去商店买(商店里面各种东西 ...

  2. ArrayList源码分析--jdk1.8

    ArrayList概述   1. ArrayList是可以动态扩容和动态删除冗余容量的索引序列,基于数组实现的集合.  2. ArrayList支持随机访问.克隆.序列化,元素有序且可以重复.  3. ...

  3. SpringMVC学习笔记之---简单入门

    SpringMVC简单入门 (一)什么是MVC设计模式 (1)model:模型数据,业务逻辑 (3)view:呈现模型,与用户进行交互 (3)controller:负责接收并处理请求,响应客户端 (二 ...

  4. Service 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  5. 【Java例题】8.2 手工编写字符串统计的可视化程序

      2. 手工编写字符串统计的可视化程序. 一个Frame窗体容器,布局为null,两个TextField组件,一个Button组件. Button组件上添加ActionEvent事件监听器Actio ...

  6. Nginx总结(一)Linux下如何安装Nginx

    以前写过一些Nginx的文章,但都是用到什么说什么,没有一个完整系统的总结.趁最近有时间,打算将Nginx相关的内容重新整理一下.nginx系列文章地址如下:https://www.cnblogs.c ...

  7. CSS布局:元素水平居中

    CSS布局之元素水平居中 本文将依次介绍在不同条件下实现水平居中多种方法 一.使用 text-align: center : 适用于块级元素内部的行内元素水平居中(也适用于图片的水平居中) 此方法对i ...

  8. Guava 常用工具类

    引入guava包: <dependency> <groupId>com.google.guava</groupId> <artifactId>guava ...

  9. 从 View 的四个构造方法说起

    View 类的四个构造函数 写过自定义 View 的都知道,View 有四个构造函数,一般大家都知道第一个构造方法是简单的在代码中new View 的时候调用的,第二个构造方法使用最广泛,是对应的生成 ...

  10. getline()与get()(c++学习笔记)

    istream中的类(如cin)提供了一些面向行的类成员函数:getline()和get() 1.getline()函数 读取整行,使用回车键输入的换行符来确定输入结尾. 调用方法:cin.getli ...