题目描述
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.

题意 : 给你两个大小为 N 的图,要求寻找既是B的子图,又和A是同构的图的数量

思路分析:刚开始一直不是很懂它的题意是要干嘛,比赛后也看了很长时间才懂一些,1-2  3 和  1  2-3 是属于同构关系的,因为都是两个点连着,一个点单独出现,因此这里只要N!枚举对应一下就可以了

1 . hash去判重

#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
const ll maxn = 1e6+5;
const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const ll inf = 0x3f3f3f3f; ll n, m1, m2;
bool mp1[10][10], mp2[10][10];
ll arr[10], d[10];
set<ll>s; void solve() {
for(ll i = 1; i <= n; i++) arr[i] = i; do{
for(ll i = 1; i <= n; i++) d[i] = arr[i]; ll sum = 0;
for(ll i = 1; i <= n; i++){
for(ll j = i+1; j <= n; j++){
if (mp2[i][j] && mp1[d[i]][d[j]]){
sum++;
}
}
}
if (sum == m1){
ll x = 0;
for(ll i = 1; i <= n; i++){
for(ll j = i+1; j <= n; j++){
if (mp1[d[i]][d[j]]) {
x+=(1LL<<(i*(n-1)+j));
}
}
}
//printf("++++ %llu \n", x);
s.insert(x);
}
}while(next_permutation(arr+1, arr+1+n));
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll a, b; while(~scanf("%d%d%d", &n, &m1, &m2)){
memset(mp1, false, sizeof(mp1));
memset(mp2, false, sizeof(mp2)); for(ll i = 1; i <= m1; i++){
scanf("%d%d", &a, &b);
mp1[a][b] = mp1[b][a] = true;
}
for(ll i = 1; i <= m2; i++){
scanf("%d%d", &a, &b);
mp2[a][b] = mp2[b][a] = true;
}
s.clear();
solve();
printf("%d\n", s.size());
}
return 0;
}

2 . 直接这样考虑,就是A图自身的同构在通过B去计算的时候,会重复算的,因此除一下就可以了

using namespace std;
#define ll unsigned long long
const ll maxn = 1e6+5;
const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const ll inf = 0x3f3f3f3f; ll n, m1, m2;
bool mp1[10][10], mp2[10][10];
ll arr[10], d[10];
set<ll>s;
int a1, a2; void solve() {
for(ll i = 1; i <= n; i++) arr[i] = i; do{
for(ll i = 1; i <= n; i++) d[i] = arr[i]; ll sum = 0;
for(ll i = 1; i <= n; i++){
for(ll j = i+1; j <= n; j++){
if (mp2[i][j] && mp1[d[i]][d[j]]){
sum++;
}
}
}
if (sum == m1){
a1++;
}
}while(next_permutation(arr+1, arr+1+n));
} void solve2() {
for(ll i = 1; i <= n; i++) arr[i] = i; do{
for(ll i = 1; i <= n; i++) d[i] = arr[i]; ll sum = 0;
for(ll i = 1; i <= n; i++){
for(ll j = i+1; j <= n; j++){
if (mp1[i][j] && mp1[d[i]][d[j]]){
sum++;
}
}
}
if (sum == m1){
a2++;
}
}while(next_permutation(arr+1, arr+1+n));
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll a, b; while(~scanf("%d%d%d", &n, &m1, &m2)){
memset(mp1, false, sizeof(mp1));
memset(mp2, false, sizeof(mp2)); for(ll i = 1; i <= m1; i++){
scanf("%d%d", &a, &b);
mp1[a][b] = mp1[b][a] = true;
}
for(ll i = 1; i <= m2; i++){
scanf("%d%d", &a, &b);
mp2[a][b] = mp2[b][a] = true;
}
s.clear();
a1 = a2 = 0;
solve();
solve2();
printf("%d\n", a1/a2);
}
return 0;
}

双射 - hash去重的更多相关文章

  1. 倒排索引 获取指定单词的文档集合 使用hash去重单词term 提高数据压缩率的方法

    倒排索引源于实际应用中需要根据属性的值来查找记录.这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址.由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而称为倒排索引(inve ...

  2. ACM-ICPC 2018 南京赛区网络预赛 I Skr (马拉车+hash去重)或(回文树)

    https://nanti.jisuanke.com/t/30998 题意 给一串由0..9组成的数字字符串,求所有不同回文串的权值和.比如说“1121”这个串中有“1”,“2”,“11”,“121” ...

  3. JavaScript-数组去重由慢到快由繁到简

    indexOf去重 Array.prototype.unique1 = function() { var arr = []; for (var i = 0; i < this.length; i ...

  4. BZOJ 2761 不重复数字 (Hash)

    题解:直接使用STL中的hash去重即可 #include <cstdio> #include <map> using namespace std; int ans[50010 ...

  5. js引用类型数组去重-对象标记法

    前言 Js数组去重已经有很多种实现方式:包括逐个检索对比(使用Array.property.indexOf),先排序后对比,使用hash表,利用ES6中的Set()等.这些数组去重办法中速度最快的是h ...

  6. JavaScript 数组去重方法总结

    1.遍历数组法: 这应该是最简单的去重方法(实现思路:新建一新数组,遍历数组,值不在新数组就加入该新数组中) // 遍历数组去重法 function unique(arr){ var _arr = [ ...

  7. 160819、JavaScript-数组去重由慢到快由繁到简

    JavaScript-数组去重由慢到快由繁到简演化   indexOf去重 Array.prototype.unique1 = function() { var arr = []; for (var ...

  8. 关于distinct 和group by的去重逻辑浅析

    在数据库操作中,我们常常遇到需要将数据去重计数的工作.例如: 表A,列col A C A B C D A B 结果就是一共出现4个不同的字母A.B.C.D 即结果为4 大体上我们可以选择count(d ...

  9. XIII Open Cup named after E.V. Pankratiev. GP of America

    A. Explosions 注意到将炸弹按坐标排序后,每个炸弹直接引爆和间接引爆的都是连续的一段区间,因此只需要求出每个炸弹能间接炸到的最左和最右的炸弹即可. 建立图论模型,炸弹$i$向炸弹$j$连单 ...

随机推荐

  1. H3C OSPF基本配置命令

  2. #干货#小微信贷风控中类IPC模式和集中审批模式

    浅析小微信贷风控中类IPC模式和集中审批模式 席占斌 常言道瑕不掩瑜,反过来讲瑜自然也不能掩瑕,看问题需要客观公正辩证. 在小微信贷中,风控模式依旧是核心,目前比较流行和占比较大的风控模式有很经典的I ...

  3. 《代码整洁之道 中文版》高清 PDF 电子书下载

    代码整洁之道.PDF 下载 代码整洁之道.PDF 中文版 高清 PDF  电子书下载 代码整洁之道下载  点我下载 作者简介  · · · · · · Robert C. Martin,Object ...

  4. C# 在 构造函数添加 CallerMemberName 会怎样

    在 C# 中有一个特性 CallerMemberName 可以给方法知道调用这个方法的方法名,在 UWP 中用这个特性很多,特别是在使用 MVVM 绑定 如果在构造函数使用这个特性会发生什么? 构造函 ...

  5. 聚类——DBSCAN

    转载自: https://www.cnblogs.com/pinard/p/6208966.html http://www.cnblogs.com/pinard/p/6217852.html http ...

  6. H3C配置BPDU的生成和传递

  7. linux 阻塞 open 作为对 EBUSY 的替代

    当设备不可存取, 返回一个错误常常是最合理的方法, 但是有些情况用户可能更愿意等待 设备. 例如, 如果一个数据通讯通道既用于规律地预期地传送报告(使用 crontab), 也用于根据 用户的需要偶尔 ...

  8. 理解Servlet

    题记:框架横行,似乎已经忘记JavaWeb最基础Servlet是如何工作的,这也是为什么要写这篇文章. Servlet是Java语言应用到Web的扩展技术,是运行在Web应用服务器上的Java程序.与 ...

  9. vue 数据监听原理

    Vue.prototype.listenDatas = function(){ for(var attr in this.$data){ this.listenData(this,attr,this. ...

  10. Struts2 注释类型

    Struts 2 应用程序可以使用Java5注释作为替代XML和Java属性配置.这里是清单的不同的类别有关的最重要的注解: 命名空间注释(动作注释): @ Namespace注释允许在Action类 ...