USTC 1119 graph 图的同构
图的同构的严格定义可以参考离散数学:The simple graphs G1=(V1,E1) and G2=(V2,E2)are isomorphic if there exists a one to one and onto function f 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 图的同构的更多相关文章
- 图的同构 (Graph Isomorphism)
整理摘自:https://www.jianshu.com/p/c33b5d1b4cd9 同构是在数学对象之间定义的一类映射,它能揭示出在这些对象的属性或者操作之间存在的关系.若这两个数学结构之间存在同 ...
- 论文解读(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 ...
- 论文解读(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 ...
- macOS 安装 Nebula Graph 看这篇就够了
本文首发于 Nebula Graph Community 公众号 背景 刚学习图数据的内容,当前网上充斥大量的安装文档,参差不齐,部署起来令人十分头疼. 现整理一份比较完整的安装文档,供大家学习参考, ...
- 论文解读(soft-mask GNN)《Soft-mask: Adaptive Substructure Extractions for Graph Neural Networks》
论文信息 论文标题:Soft-mask: Adaptive Substructure Extractions for Graph Neural Networks论文作者:Mingqi Yang, Ya ...
- [开发笔记] Graph Databases on developing
TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- [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), ...
随机推荐
- RAMOS系统 WIN7+VHD+GURB map
转载(并未验证) 前段时间加了一个内存条,将笔记本内存升级到了6G,由于之前用的是32位的win7不可以直接使用6G内存,便装了64位的系统.网上找资源的时候发现,大内存可以使用RamOS,从内存中虚 ...
- jfreechart图表汉字乱码问题解决方案
系统工作迁移环境 linux centos 6.5 tomcat8 mysql5.6 系统部署上之后,所有的jfreechart图表上的汉字,全部乱码. 如图: 经分析: 1)数据库动态读出来的是正常 ...
- 纠错输出编码法ECOC
纠错输出编码法(Error-Correcting Output Codes,ECOC)不仅能够将多类分类问题转化为多个两类问题,而且利用纠错输出码本身具有纠错能力的特性,可以提高监督学习算法的预测精度 ...
- QT移植
QT下载地址:http://download.qt.io/archive/qt/1.编译tslib(touch screen lib) 准备工作:确保以下工具安装完成 sudo apt-get ins ...
- 我用Cocos2d-x模拟《Love Live!学院偶像祭》的Live场景(一)
同样从CSDN搬过来 博客开这么久了,就发过一篇很水的文章,一直想写点正式的东西.这次准备开工一个仿其他游戏的简单小游戏,于是开博客把开发过程记录下来.这一系列文章主要讲,我是如何从零开始使用Coco ...
- mysql5.5慢日志设置和查询
mysql> showvariables like '%version%'; +-------------------------+---------------------+ | Variab ...
- JS加载相对路径脚本的方法 - 汇总
js加载脚本的方式有很多,但是各有各的用途. 最近公司https项目改造,对于资源文件这一块,也是遇到一些问题,现在就来总结一下,怎样改造https的脚本吧~! 方法1.借助服务端语言如PHP,输入当 ...
- .NET操作RabbitMQ组件EasyNetQ使用中文简版文档。
本文出自EasyNetQ官方文档,内容为自己理解加翻译.文档地址:https://github.com/EasyNetQ/EasyNetQ/wiki/Quick-Start EasyNetQ简介 Ea ...
- 你真的了解如何将 Nginx 配置为Web服务器吗
阅读之前,建议先阅读初识 Nginx. 之后,我们来了解一下 Nginx 配置. 抽象来说,将 Nginx 配置为 Web 服务器就是定义处理哪些 URLS 和如何处理这些URLS 对应的请求.具体来 ...
- MongoDB基础之一:Conetos下安装MongoDB
1.下载自己需要的版本,我这用的是mongodb-linux-x86_64-2.4.9.tgz #cd /usr/local/src # wget http://fastdl.mongodb.org/ ...