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

最新文章

  1. C#给PDF文档添加文本和图片页眉
  2. the request resource is not available
  3. 解决maven创建web项目卡死在generator插件(转)
  4. SVN中trunk、branches、tags用法详解
  5. C扩展Python
  6. Andorid-Fragment生命周期
  7. java web 前端页面的分页逻辑
  8. 【Jquery EasyUI + Servlet】DataGrid,url请求带中文出现乱码的解决方案
  9. BZOJ 1367([Baltic2004]sequence-左偏树+中位数贪心)
  10. cp2102 驱动 win7x64 -2018
  11. 【转】Android中dip(dp)与px之间单位转换
  12. Code review应该怎么做
  13. Laravel 5.4设置logout注销账户的重定向路径
  14. Spring事务管理(详解+实例)
  15. css相关知识点
  16. ASP.NET MVC如何在Action中返回脚本并执行
  17. Unity3d游戏地图生成器MapMagic World Generator v1.9.1
  18. 用python开发android应用 【转载】
  19. [原][译][physX]phsyX3.3.4官方文档物理引擎基本概念和例子介绍
  20. ecshop hash登录 + wordpress mysql盲注字段

热门文章

  1. laravel构造函数和中间件执行顺序问题
  2. P1048 数组中的逆序对
  3. jQuery 工具类函数-URL操作函数
  4. dll中全局变量在外部进行引用
  5. &lt;QluOJ2018NewCode&gt;计算几何(寄蒜几盒)
  6. CSS兼容性问题的解决方式(更新中&#183;&#183;&#183;)
  7. [vue/no-parsing-error] Parsing error: x-invalid-end-tag.eslint-plugin-vue
  8. k8s数据持久化实验
  9. C# 获取控制台程序路径
  10. delphi 子窗体最大化