题目描述
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. git卡在Resolving deltas 100%的解决办法

    很多同学都有这样的问题.不知道是git的问题,还是tortoisegit的问题. 我的版本: Git-1.8.4-preview20130916 TortoiseGit-1.8.6.0-32bit 已 ...

  2. Scheduler

    先看看文档对于Scheduler的作用介绍 https://code4craft.gitbooks.io/webmagic-in-action/content/zh/posts/ch1-overvie ...

  3. mysql ”Invalid use of null value“ 解决方法

    1.问题描述 因为要更改"information"表中的"编号"列为非空,使用数据库查询语句“alter table information modify '编 ...

  4. MySQL——修改视图

    修改视图是指修改数据库中存在的视图,当基本表的某些字段发生变化时,可以通过修改视图来保持与基本表的一致性. 1.  用  CREATE  OR  REPLACE   VIEW  语句修改视图 语法格式 ...

  5. 【t046】牛跳

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] John的奶牛们计划要跳到月亮上去.它们请魔法师配制了P(1 <= P <=150,000 ...

  6. The Function() Constructor

    Functions are usually defined using the function keyword, either in the form of a function definitio ...

  7. P1048 数组中的逆序对

    题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. 输入格式 第一行包含一个整数 \(n\) ,表示数组中的元素个数 ...

  8. linux 系统挂起

    尽管内核代码的大部分 bug 以 oops 消息结束, 有时候它们可能完全挂起系统. 如果系 统挂起, 没有消息打印. 例如, 如果代码进入一个无限循环, 内核停止调度,[15]15 并且系 统不会响 ...

  9. C# 文件在数据库 的 存取

    ... /// <summary> /// 获取数据库Image字段数据,保存到本地 /// </summary> /// <param name="sende ...

  10. 安装低版本Microsoft .NET Framework 4.5受阻解决方案

    在VS目标框中找不到Microsoft .NET Framework 4.5,项目出错,安装受阻.... 1.Microsoft .NET Framework 安装了高版本后,低版本通过网上上下载的d ...