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), ...
随机推荐
- UVa 10427 - Naughty Sleepy Boys
题目大意:从1开始往后写数字,构成一个如下的字符串 123456789101112... .求第n位的数字是多少. 找规律,按数字的位数可以构建一个类似杨辉三角的东西,求出第n位是哪个数的第几位即可. ...
- 如何使用Grunt(好文)
Grunt 是什么? Grunt 基于Node.js之上,是一个以任务处理为基础的命令行工具,可以减少优化开发版本为发布版本所需的人力和时间,从而加速开发流程.它的工作原理是把这 些工作整合为不同的任 ...
- 如何解决PHP+MySQL出现乱码的现象
在使用PHP+MYSQL时,您是否遇到过字符乱码的问题呢?您是如何解决这个问题的呢?这里提供了一种解决之道. 在mysql_connect后面加一句SET NAMES UTF8,即可使得UTF8的数据 ...
- YII 1.0 扩展第三方类
扩展缩略图类在blog\protected\extensions 中建立 Image/CThumb.php 1. 自己瞎弄的,一点都不优雅 include_once Yii::app()->Ba ...
- nginx集群tomcat
一.准备工作 下载nginx,http://nginx.org/,本文采用nginx-1.8.0,下载之后直接解压,免安装 下载tomcat,以配置3台tomcat服务器做负载均衡为例 二.修改tom ...
- Backbone源码解读(一)事件模块
Backbone源码浅读: 前言: Backbone是早起的js前端MV*框架之一,是一个依赖于underscore和jquery的轻量级框架,虽然underscore中基于字符串拼接的模板引擎相比如 ...
- treegrid.bootstrap使用说明
treegrid.bootstrap使用说明 这个插件是用来做有层次的表格的,大概如图: 官网 http://maxazan.github.io/jquery-treegrid/ 使用这个控件之前需 ...
- MyBatis 插入时返回自增主键
XML <insert id="insert" parameterType="com.stone.model.Person"> <!-- se ...
- FMS4中的P2P功能
在fms4以前Adobe只允许在stratus中才能使用p2p功能.令人高兴的是,在最新发布的fms4中,p2p功能已经集成进来了,这将给实时视频类的应用带来更高的效率,adobe这次很给力! 为了使 ...
- bootstrap 表单控件 控件状态 控件大小 help-block
bootstrap 表单控件 控件状态 控件大小 help-block <!DOCTYPE html> <html lang="en"> <head& ...