USTC 1119

图的同构的严格定义可以参考离散数学:The simple graphs G1=(V1,E1) and G2=(V2,E2)are isomorphic if there exists a one to one and onto function from V1 to V2 with the property that a and b are adjacent in G1 if and only if f(a)and f(b) are adjacent G2 , for all a and b in V1.

用哈希映射的方法可以解决,这个题的数据规模比较小,应该可以解决规模更大的题目。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=30,maxm=300,K=10,A=7,B=3,C=4,P=10007,D=35;
int a[maxm][2],co[maxn],f[maxn],tf[maxn],n,m,cot[maxn];
void graph_hash()
{
int q,w,e;
for(int i=1;i<=n;i++)
{
for( q=1;q<=n;q++)f[q]=1;
for(int z=0;z<K;z++)
{
memcpy(tf,f,sizeof(f));
for(q=1;q<=n;q++)f[q]*=A;
for(q=0;q<m;q++)
{
f[a[q][0]]+=tf[a[q][1]]*B;
f[a[q][1]]+=tf[a[q][0]]*C;
}
f[i]+=D;
for(q=1;q<=n;q++)f[q]%=P;
}
co[i]=f[i];
}
sort(co+1,co+1+n);
}
int main()
{
int kt;scanf("%d",&kt);
for(int ii=0;ii<kt;ii++)
{
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
scanf("%d%d",&a[i][0],&a[i][1]);
a[i+m][0]=a[i][1];
a[i+m][1]=a[i][0];
}
m=m*2;
graph_hash();
memcpy(cot,co,sizeof(co));
m=m/2;
for(int i=0;i<m;i++)
{
scanf("%d%d",&a[i][0],&a[i][1]);
a[i+m][0]=a[i][1];
a[i+m][1]=a[i][0];
}
m=m*2;
graph_hash();
bool ans=true;
for(int i=1;i<=n;i++)
{
if(cot[i]!=co[i]){ans=false;break;}
}
if(ans==false){printf("different\n");}
else printf("same\n");
}
return 0;
}

  

USTC 1119 graph 图的同构的更多相关文章

  1. 图的同构 (Graph Isomorphism)

    整理摘自:https://www.jianshu.com/p/c33b5d1b4cd9 同构是在数学对象之间定义的一类映射,它能揭示出在这些对象的属性或者操作之间存在的关系.若这两个数学结构之间存在同 ...

  2. 论文解读(GMI)《Graph Representation Learning via Graphical Mutual Information Maximization》2

    Paper Information 论文作者:Zhen Peng.Wenbing Huang.Minnan Luo.Q. Zheng.Yu Rong.Tingyang Xu.Junzhou Huang ...

  3. 论文解读(GMI)《Graph Representation Learning via Graphical Mutual Information Maximization》

    Paper Information 论文作者:Zhen Peng.Wenbing Huang.Minnan Luo.Q. Zheng.Yu Rong.Tingyang Xu.Junzhou Huang ...

  4. macOS 安装 Nebula Graph 看这篇就够了

    本文首发于 Nebula Graph Community 公众号 背景 刚学习图数据的内容,当前网上充斥大量的安装文档,参差不齐,部署起来令人十分头疼. 现整理一份比较完整的安装文档,供大家学习参考, ...

  5. 论文解读(soft-mask GNN)《Soft-mask: Adaptive Substructure Extractions for Graph Neural Networks》

    论文信息 论文标题:Soft-mask: Adaptive Substructure Extractions for Graph Neural Networks论文作者:Mingqi Yang, Ya ...

  6. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  7. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  8. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  9. [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

随机推荐

  1. struts2默认Action配置

    在项目中,需要在输入错误的url的时候,弹出友好的错误提示页面 在struts2中可以通过配置默认的action达到这个目的 配置方法: <package name="default& ...

  2. php AES 加密类

    <?php class CryptAES { protected $cipher = MCRYPT_RIJNDAEL_128; protected $mode = MCRYPT_MODE_ECB ...

  3. iOS 之 内存管理

    凡是alloc copy mutablecopy init 声明的变量,都需要通过手动的方式进行释放,realse. 如果 copy一个对象,则拥有了拷贝的对象,要负责释放. 如果 保持(retain ...

  4. 一个简单的Java集合范围过滤的多个方式对比

    在一个项目里面有这么一个技术需求: 1.集合中元素个数,10M 2.根据上限和下限从一个Set中过滤出满足要求的元素集合. 实际这个是个很典型的技术要求, 之前的项目也遇见过,但是因为当时的类库不多, ...

  5. JS之ONLoad事件

    如果我问你window.load和window.onload分别是什么意思,恐怕你会回答我:“这不是页面加载完就执行吗”. 但是答案是不一定,得看你怎么用.看一下例子吧 例1: <!DOCTYP ...

  6. jQuery选择器,用逗号分隔的时候需要注意范围问题

    jQuery选择器,用逗号分隔的时候需要注意范围问题: <%@ page language="java" import="java.util.*" pag ...

  7. Weblogic常见故障常:JDBC Connection Pools

    http://blog.csdn.net/woshixuye/article/details/24122579 有些时候是数据库连接池出现了问题,测试的时候显示没有连接池了,重启WebLogic都不行 ...

  8. SQL2008实现数据库自动定时备份——维护计划

    在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库.而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求管理员 每天守到晚上1点去备份数据库.要实现数据库的 ...

  9. PowerDesigner如何把建好的表导入到数据库中,并且把注释也导入进去

    第一次接触这个软件,经过自己的捣鼓和百度,终于可以顺利的导入数据库中了,好开森,希望可以帮助到更多人. 数据库(mysql)其实和sqlserver差不多,以16.5版本为例 1.选中一个PDM项目, ...

  10. rf对时间控件的操作

    1.如何去掉readonly属性 前端对于时间控件的设置,有时是为了限制用户不能进行手动输入方式进行选择时间,避免在手动输入的时候超限或者输入格式不正确,导致一些不必要的验证麻烦,这是前端开发工程师就 ...