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. 关键词匹配(Ac自动机模板题)

    2772: 关键词匹配 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 10  Solved: 4[Submit][Status][Web Board] ...

  2. ios framework 开发实战 之 参考

    WWDC2014之iOS使用动态库 iOS开发——创建你自己的Framework 使用CocoaPods开发并打包静态库 iOS Framework 和CocoaPods TDD的iOS开发初步以及K ...

  3. 使用python爬虫抓站的一些技巧总结:进阶篇

    Reference:http://python.jobbole.com/82000/ 一.gzip/deflate支持 现在的网页普遍支持gzip压缩,这往往可以解决大量传输时间,以VeryCD的主页 ...

  4. django的HTTPREQUEST对象

    Django使用request和response对象 当请求一张页面时,Django把请求的metadata数据包装成一个HttpRequest对象,然后Django加载合适的view方法,把这个Ht ...

  5. php调用js变量

    <script> function tuichu(skp){ <?php $ok="skp"; echo "alert($ok)";//实验代 ...

  6. .net 设置版本号信息

    1.AssemblyInfo.cs [assembly: AssemblyVersion("1.3.170116")] [assembly: AssemblyFileVersion ...

  7. ui-router---$stateProvider

    转自:http://blog.csdn.net/violet_day/article/details/17515157 $stateProvider $stateProvider.state(stat ...

  8. magento1.x 运行在 php7 优惠券的问题

    diff --git app/code/core/Mage/Sales/etc/config.xml index 5bb43d7..7db62ca 100644 --- app/code/core/M ...

  9. #图# #SPFA# ----- codevs1021 玛丽卡

    codevs1021 玛丽卡 题目描述 Description麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复.因为她和他们不住在同一个城市,因此她开始准备她的长途旅行.在这个国家中每两个城市之间最多 ...

  10. JQuery hover toggle事件使用

    JQuery hover toggle事件使用: <%@ page language="java" import="java.util.*" pageEn ...