链接: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. P1372 又是毕业季I

    题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚在毕业晚会上,相信,这一定 ...

  2. lua centos 安装报错

    yum install libtermcap-devel ncurses-devel libevent-devel readline-devel

  3. 公众号如何获取已关注用户的unionid的问题

    避免误导,先加一句:首先,得公众号绑定开放平台 这个问题困扰了我一早上,我尝试了很多次获取unionid都失败. 微信的开发文档上有说: 关于特殊场景下的静默授权 1.上面已经提到,对于以snsapi ...

  4. java 生成特定范围内的随机数

    /** * 生成[1, max]之间的随机数 */ public static Integer getRandomNumber(Integer max) { Random rd = new Rando ...

  5. InChatter系统之服务端的Windows服务寄宿方式(三)

    为了部署的方便,我们开发Windows服务的服务寄宿程序,这样我们的服务便可以作为系统服务,随着系统的启动和关闭而启动和关闭,而避免了其他的设置,同时在服务的终止时(如系统关闭等)能及时处理服务的关闭 ...

  6. Java.io.ObjectOutputStream.writeObject()方法实例

    java.io.ObjectOutputStream.writeObject(Object obj) 方法将指定对象写入ObjectOutputStream.该对象的类,类的签名,以及类及其所有超类型 ...

  7. ECharts 3.0 初学感想及学习中遇到的瓶颈

    因为刚工作的原因,压力特别大,加上时间也不是很充足,所以最近也没怎么整理学习的东西,今天趁着手头工作完成总结一下吧, 说实话,其实ECharts 就是图表绚丽,展示数据渲染效果更加强烈,从2.0到3. ...

  8. org.apache.tomcat.util.net.NioEndpoint,打开的文件过多

    错误信息: 27-Mar-2019 04:20:20.430 严重 [http-nio-8100-Acceptor-0] org.apache.tomcat.util.net.NioEndpoint$ ...

  9. java将字段映射成另一个字段,关于 接口传参 字段不对应转换

    在接口开发中我们经常会遇到一个问题,打个比方,我们的实体类A中有两个字段user和pwd但是接口中需要username和password这怎么办呢,我想到了两种方法:1.新创建一个实体类B或者new一 ...

  10. charsets - 程序员对字符集和国际化的观点

    描述 Linux 是一个国际性的操作系统.它的各种各样实用程序和设备驱动程序 (包括控制台驱动程序 ) 支持多种语言的字符集,包括带有附加符号的拉丁字母表字符,重音符,连字(字母结合), 和全部非拉丁 ...