链接:https://www.nowcoder.com/acm/contest/139/D
来源:牛客网

同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所有的x,y∈V均有xy∈E等价于m(x)m(y)∈E1,则称G和G1是同构的,这样的一个映射m称之为一个同构,如果G=G1,则称他为一个自同构。

题目描述

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.

输入

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. 题意 两个简单无向图,g1,g2.问g2的子图中有多少个是g1的同构图
解析 点的数量是8我们不能用边来枚举子图 数量太多了 我们可以把点全排列按照映射的关系去找边是否存在 再把重复的去掉就是答案
去重可以用二进制压缩边集set去重,也可以哈希,除以自同构数量,暴力。。。。
自同构数求法 枚举全排列映射到本身g1 如果图完全一样 计下数。
代码:
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f,maxn=,mod=1e9+;
typedef long long ll;
int n,m1,m2,u[maxn*],v[maxn*],g1[maxn][maxn],g2[maxn][maxn],a[maxn];
int main()
{
while(scanf("%d%d%d",&n,&m1,&m2)!=EOF)
{
memset(g1,,sizeof(g1));
memset(g2,,sizeof(g2));
for(int i=;i<=m1;i++)
{
scanf("%d%d",&u[i],&v[i]);
g1[u[i]][v[i]]=g1[v[i]][u[i]]=;
}
for(int i=;i<=m2;i++)
{
int x,y;
scanf("%d%d",&x,&y);
g2[x][y]=g2[y][x]=;
}
for(int i=;i<=n;i++)a[i]=i;
int ans=,num=;
do
{
int flag1=,flag2=;
for(int i=;i<=m1;i++)
{
int x=a[u[i]],y=a[v[i]];
if(!g1[x][y])flag1=;
if(!g2[x][y])flag2=;
}
ans+=flag2;
num+=flag1;
}while(next_permutation(a+,a+n+));
printf("%d\n",ans/num);
}
return ;
}
//5 3 7
//1 2
//1 3
//1 4
//1 2
//1 3
//1 4
//2 4
//3 4
//4 5
//2 5

暴力版 就是先存下一个同构图temp  在所有的里面找与temp行列式完全相同的有多少个 就是自同构的数量

#include<bits/stdc++.h>
using namespace std;
const int maxn=10,mod=1e9+7;
typedef long long ll;
int g1[maxn][maxn],g2[maxn][maxn],g3[maxn][maxn];
int a[maxn],temp[maxn][maxn];
int main()
{
int n,m1,m2;
while(cin>>n>>m1>>m2)
{
int x,y;
memset(g1,0,sizeof(g1));
memset(g2,0,sizeof(g2));
for(int i=0;i<m1;i++)
{
cin>>x>>y;
g1[x][y]=g1[y][x]=1;
}
for(int i=0;i<m2;i++)
{
cin>>x>>y;
g2[x][y]=g2[y][x]=1;
}
for(int i=1;i<=n;i++)a[i]=i;
do{
int flag=0;
memset(temp,0,sizeof(temp));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(g1[i][j]==1)
{
if(g2[a[i]][a[j]]==0)
{
flag=1;break;
}
else
temp[a[i]][a[j]]=1;
}
}
if(flag)break;
}
if(!flag)break;
}while(next_permutation(a+1,a+n+1));
for(int i=1;i<=n;i++)a[i]=i;
int ans=0,num=0;
do{
int flag=0;
memset(g3,0,sizeof(g3));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(g1[i][j]==1)
{
if(g2[a[i]][a[j]]==0)
{
flag=1;break;
}
else
g3[a[i]][a[j]]=1;
}
}
if(flag)break;
}
if(!flag)
{
ans++;
for(int i=1;i<=n;i++)//{
for(int j=1;j<=n;j++)
if(temp[a[i]][a[j]]!=g3[a[i]][a[j]])flag=1;
if(!flag)num++;
} }while(next_permutation(a+1,a+n+1));
//cout<<ans<<" "<<num<<endl;
cout<<ans/num<<endl;
}
}
J题 区间之外不同数的个数 复制数组 主席树 过的 正解是 离线+树状数组 记录下第一次出现和最后一次出现的位置
代码
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

const int maxn = 2e5 + ;
int n,q; int cnt = ; struct Node
{ int l,r,sum; } p[maxn*];
int la[maxn];
int a[maxn]; int root[maxn]; int build(int l,int r)
{ int nc = ++cnt; p[nc].sum = ; p[nc].l = p[nc].r = ; if (l == r) return nc; int m = l + r >> ; p[nc].l = build(l,m); p[nc].r = build(m+,r); return nc; }
int update(int pos,int c,int v,int l,int r)
{
int nc = ++cnt;
p[nc] = p[c];
p[nc].sum += v;
if (l == r) return nc;
int m = l+r>>;
if (m >= pos)
{
p[nc].l = update(pos,p[c].l,v,l,m);
}
else
{
p[nc].r = update(pos,p[c].r,v,m+,r);
}
return nc;
}
int query(int pos,int c,int l,int r)
{
if (l == r) return p[c].sum;
int m = l + r >> ;
if (m >= pos)
{
return p[p[c].r ].sum + query(pos,p[c].l,l,m);
}
else return query(pos,p[c].r,m+,r);
}
int main()
{
while(scanf("%d%d",&n,&q)!=EOF)
{ memset(la,-,sizeof la);
cnt=;
for (int i = ; i <= n; ++i)
{
scanf("%d",a+i);
}
for(int i=n+; i<=*n; i++)
a[i]=a[i-n];
n=n*;
root[] = build(,n);
for (int i = ; i <= n; ++i)
{
int v = a[i];
if (la[v] == -)
{
root[i] = update(i,root[i-],,,n);
}
else
{
int t = update(la[v],root[i-],-,,n);
root[i] = update(i,t,,,n);
}
la[v] = i;
}
while(q--)
{
int x,y;
scanf("%d %d",&x, &y);
printf("%d\n",query(y,root[n/+x],,n));
} }
}


2018牛客网暑期ACM多校训练营(第一场)D图同构,J的更多相关文章

  1. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  2. 2018 牛客网暑期ACM多校训练营(第一场) E Removal (DP)

    Removal 链接:https://ac.nowcoder.com/acm/contest/139/E来源:牛客网 题目描述 Bobo has a sequence of integers s1, ...

  3. 2018牛客网暑期ACM多校训练营(第十场)A Rikka with Lowbit (树状数组)

    链接:https://ac.nowcoder.com/acm/contest/148/A 来源:牛客网 Rikka with Lowbit 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C ...

  4. 2018牛客网暑期ACM多校训练营(第十场)J Rikka with Nickname(二分,字符串)

    链接:https://ac.nowcoder.com/acm/contest/148/J?&headNav=acm 来源:牛客网 Rikka with Nickname 时间限制:C/C++ ...

  5. 2018牛客网暑期ACM多校训练营(第二场)J Farm(树状数组)

    题意 n*m的农场有若干种不同种类作物,如果作物接受了不同种类的肥料就会枯萎.现在进行t次施肥,每次对一个矩形区域施某种类的肥料.问最后枯萎的作物是多少. 分析 作者:xseventh链接:https ...

  6. 2018牛客网暑期ACM多校训练营(第一场)B Symmetric Matrix(思维+数列递推)

    题意 给出一个矩阵,矩阵每行的和必须为2,且是一个主对称矩阵.问你大小为n的这样的合法矩阵有多少个. 分析 作者:美食不可负064链接:https://www.nowcoder.com/discuss ...

  7. 2018牛客网暑期ACM多校训练营(第三场) A - PACM Team - [四维01背包][四约束01背包]

    题目链接:https://www.nowcoder.com/acm/contest/141/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

  8. 2018牛客网暑期ACM多校训练营(第五场) F - take - [数学期望][树状数组]

    题目链接:https://www.nowcoder.com/acm/contest/143/F 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

  9. 2018牛客网暑期ACM多校训练营(第五场) E - room - [最小费用最大流模板题]

    题目链接:https://www.nowcoder.com/acm/contest/143/E 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

随机推荐

  1. 在reset css后两个input之间还是出现默认间隔的问题。

    <div class="search_box fl"> <input type="text" class="search_text& ...

  2. Angular广播/消息通知的接收与发送

    一.在接收页:添加引用: private eventManager: JhiEventManager: 接收通知的方法: // 接收通知(新建.编辑.删除页发送过来的通知) // upmsMenuLi ...

  3. q-oo-p , a piggy domain name. Very cute. boyan.zheng at foxmail.com

    Contact me.

  4. 迅为iTOP-4418嵌入式开发板初体验

    iTOP-4418开发板预装 Android4.4.4 系统, 支持9.7 寸.7 寸.4.3 寸屏幕. 参数:核心板参数 尺寸 50mm*60mm高度 核心板连接器为1.5mmCPU ARM Cor ...

  5. 从mysql全库备份中恢复指定库和指定表

    需求:开发要求导入某天某个表的数据,而我们的数据是全库备份 例如:  从newbei_2017-08-31_402793782.tar.bz2中恢复表:bei_table 的数据 一.备份策略 备份全 ...

  6. 查看外网IP

    同一个网络,登录不同网站/APP, 显示的登录IP可能不一样. 输入ip138.com 得到外网IP: 输入:http://www.net.cn/static/customercare/yourip. ...

  7. ssd遇到的bug

    从训练一开始就loss为0: 最开始以为是在生成train.lmdb前没有对label_map进行修改,发现并不是这个问题 1.训练的命令是:python ./examples/ssd/ssd_pas ...

  8. 【转】MFC 自定义edit 限制输入十六进制内容 响应复制粘贴全选剪切的功能

    参考地址:MFC 自定义edit 限制输入内容 响应复制粘贴全选剪切的功能   Ctrl组合键ASCII码 ^Z代表Ctrl+z                     ASCII值 控制字符  AS ...

  9. 网页显示403. That’s an error的解决方法。

    使用Go*gent打开网页,经常出现403. That’s an error.下面是解决的方法.   方法/步骤   一.打开Go*gent的文件目录.不知道找文件目录的,可以在桌面上右键点击Go*g ...

  10. 《Java程序设计》课程试题

    < Java程序设计 >课程试题 一.单项选择题(20题:每题2分,共40分) 1.若数组a定义为int[][]a=new int[3][4],则a是___. A)一维数组 B)二维数组 ...