Two Graphs 牛客网暑期ACM多校训练营(第一场)D 图论基础知识 全排列
链接:https://www.nowcoder.com/acm/contest/139/D
来源:牛客网
Given two graphs
*
* 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 ≤ 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 图论基础知识 全排列的更多相关文章
- 牛客网暑期ACM多校训练营 第九场
		
HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a ...
 - 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)
		
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...
 - 牛客网暑期ACM多校训练营(第五场):F - take
		
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...
 - 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
		
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
 - 牛客网 暑期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 ,问你 ...
 - 牛客网暑期ACM多校训练营(第三场)H  Diff-prime Pairs (贡献)
		
牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...
 - 2018牛客网暑期ACM多校训练营(第二场)I- car  ( 思维)
		
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
 - 2018牛客网暑期ACM多校训练营(第一场)D图同构,J
		
链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...
 - 牛客网暑期ACM多校训练营(第七场)Bit Compression
		
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...
 
随机推荐
- poj 1050 To the Max(最大子矩阵之和)
			
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
 - Cell Phone Networ (树形dp-最小支配集)
			
目录 Cell Phone Networ (树形dp-最小支配集) 题意 思路 题解 Cell Phone Networ (树形dp-最小支配集) Farmer John has decided to ...
 - oracle-11g2下载安装笔记
			
一.下载链接地址 http://download.oracle.com/otn/nt/oracle11g/112010/win64_11gR2_database_1of2.zip http://dow ...
 - Tomcat+MySQL常见调优参数
			
一.Tomcat 调优 (一).Tomcat内存优化 参数一: vim /tomcat/bin/catalina.sh CATALINA_OPTS="-server -Xms128m -Xm ...
 - 手摸手,带你用vue实现后台管理权限系统及顶栏三级菜单显示
			
手摸手,带你用vue实现后台管理权限系统及顶栏三级菜单显示 效果演示地址 项目demo展示 重要功能总结 权限功能的实现 权限路由思路: 根据用户登录的roles信息与路由中配置的roles信息进行比 ...
 - JAVA基础知识(八)值传递与引用传递
			
值传递:(形式参数类型是基本数据类型):方法调用时,实际参数把它的值传递给对应的形式参数,形式参数只是用实际参数的值初始化自己的存储单元内容,是两个不同的存储单元,所以方法执行中形式参数值的改变不影响 ...
 - JavaScript数据结构——队列的实现与应用
			
队列与栈不同,它遵从先进先出(FIFO——First In First Out)原则,新添加的元素排在队列的尾部,元素只能从队列头部移除. 我们在前一篇文章中描述了如何用JavaScript来实现栈这 ...
 - java NIO知多少
			
背景 Linux系统中的IO操作内部相当复杂,下面是一张带图片的LinuxIO相关层级关系: 下面是一个简化版本Linux内部IO层级图: 对此我的理解,java程序员版本的IO理解: java中的I ...
 - Cause: java.lang.NumberFormatException: For input string: "D"
			
异常:Cause: java.lang.NumberFormatException: For input string: "D" 问题回显: 原因分析:'D'只有1位,被认为是ch ...
 - 原来update还可以这么用,一切都是这么神奇。
			
update sys_user_info a left join union_menber_info b on a.user_cardno = b.member_cardno set a.user_s ...