题目描述
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. 【a403】遍历树问题

    Time Limit: 1 second Memory Limit: 32 MB [问题描述] 我们都很熟悉二叉树的前序.中序.后序遍历,在数据结构中常提出这样的问题:已知一棵二叉树的前序和中序遍历, ...

  2. activeMQ的两个默认端口8161和61616的区别

    activeMQ默认配置下启动会启动8161和61616两个端口,其中8161是mq自带的管理后台的端口,61616是mq服务默认端口 . 8161是后台管理系统,61616是给java用的tcp端口 ...

  3. MySQL面试(二)

    1.为什么索引遵循最左匹配原则? 当B+树的数据项是符合的数据结构,比如(name,age,sex)的时候,B+树是按照从左到右的顺序建立搜索树的.比如当(张三,20,F)这样的数据来检索的时候,b+ ...

  4. asp dotnet core 通过图片统计 csdn 用户访问

    在 csdn 的访问统计里面,只能用 csdn 提供的访问统计,因为在 csdn 中不支持在博客加上 js 代码,也就是无法使用友盟等工具统计. 通过在 asp dotnet core 创建一个图片链 ...

  5. 【43.49%】【hdu3308】LCIS

    Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  6. 解决应用服务器变为集群后的Session问题

    2.2.4.2 解决应用服务器变为集群后的Session问题 先来看一下什么是Session. 用户使用网站的服务,基本上需要浏览器与Web 服务器的多次交互.HTTP 协议本身是无状态的,需要基于H ...

  7. vue-learning:23 - js - leftcycle hooks

    vue 生命周期钩子函数 每一个Vue实例在创建时都需要经过一系列初始化.根据vue实例化过程中执行的逻辑,可以分为5个阶段: 初始化阶段 模板编译阶段 虚拟DOM挂载阶段 响应更新阶段 卸载阶段 这 ...

  8. 2018-10-18-WPF-跨线程-UI-的方法

    title author date CreateTime categories WPF 跨线程 UI 的方法 lindexi 2018-10-18 10:25:28 +0800 2018-10-18 ...

  9. MyBatis整合Spring MVC(易百教程)

    MyBatis是ibatis的升级版,作为hibernate的老对手,它是一个可以自定义SQL.存储过程和高级映射的持久层框架.与Hibernate 的主要区别就是 Mybatis 是半自动化的,而 ...

  10. 我们基于kaldi开发的嵌入式语音识别系统升级成深度学习啦

    先前的文章<三个小白是如何在三个月内搭一个基于kaldi的嵌入式在线语音识别系统的>说我们花了不到三个月的时间搭了一个基于kaldi的嵌入式语音识别系统,不过它是基于传统的GMM-HMM的 ...