牛客网暑期ACM多校训练营(第一场):D-Two Graphs
链接:D-Two Graphs
题意:给出图G1和G2,求G2的子图中和G1同构的个数。
题解:只有8个点,暴力枚举G2的点每个排列,让G1映射到G2中,求出同构个数a。同构的G2就是在G1有边的对应位置也有边。在求一G1到G1的全排列映射的同构个数b。答案就是a/b。因为每一个和G1同构的子图都会重复计算b次。
#include <bits/stdc++.h>
using namespace std; const double EPS = 1e-;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
const int maxn = + ;
int n, m1, m2;
int g1[maxn][maxn], g2[maxn][maxn];
int a[maxn], b[maxn]; int Cal(int g1[][maxn], int g2[][maxn])
{
for(int i = ; i < n; i++) a[i] = i + ; int ans = ;
do{
for(int i = ; i < n; i++) b[a[i]] = i + ;
bool ok = true;
for(int i = ; i <= n; i++){
for(int j = ; j <= n; j++){
if(g1[i][j] == && g2[b[i]][b[j]] != ){
ok = false;
break;
}
}
}
if(ok) ans++;
}while(next_permutation(a, a + n)); return ans;
} int main()
{
while(scanf("%d%d%d", &n, &m1, &m2) != EOF){
memset(g1, , sizeof(g1));
for(int i = , a, b; i < m1; i++){
scanf("%d%d", &a, &b);
g1[a][b] = ;
g1[b][a] = ;
}
memset(g2, , sizeof(g2));
for(int i = , a, b; i < m2; i++){
scanf("%d%d", &a, &b);
g2[a][b] = ;
g2[b][a] = ;
} printf("%d\n", Cal(g1, g2) / Cal(g1, g1));
} return ;
}
牛客网暑期ACM多校训练营(第一场):D-Two Graphs的更多相关文章
- 牛客网暑期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秒 ...
- 牛客网暑期ACM多校训练营(第七场)Bit Compression
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...
- 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
随机推荐
- redis hash类型
- Hive 常用命令和语句
示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...
- Spring boot 集成三种定时任务方式
三种定时任务方式分别为 org.springframework.scheduling.annotation.Scheduled java.util.concurrent.ScheduledExecut ...
- Strut2 的 Action获取JSP 页面参数的方法
struts2 Action获取表单传值1.通过属性驱动式JSP:<form action="sys/login.action" method="post" ...
- javascript入门笔记8-window对象
History 对象 history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能. 注意:从窗口被打开的那一刻开始记录,每个浏览器窗口.每个标签页乃至每个框架,都 ...
- es6-promise.auto.js
使用sweetalert2的IE浏览器报错,导入文件 链接:https://pan.baidu.com/s/1mOcsN_o8m-7I7Rej1NPkiw 提取码:9xsj
- [JZOJ] 5905. 黑暗之魂(darksoul)
基环树直径裸题 分别在子树做DP,环上做DP,环上可以用单调队列优化到\(O(n)\) 写起来很麻烦 #include<algorithm> #include<iostream> ...
- Mysql查看锁等信息SQL语句
查看锁等信息,包括锁信息: select "HOLD:",ph.id h_processid,trh.trx_id h_trx_id,trh.trx_started h_start ...
- datatable 默认按某字段排序
"columns": [ { data: null}, { data: 'name'}, { data: 'birthday'} ], "order": [[ ...
- 使用 python快速搭建http服务
在 Linux 服务器上或安装了 Python 的机器上,Python自带了一个WEB服务器 SimpleHTTPServer. 我们可以很简单的使用 python -m SimpleHTTPSer ...