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.

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

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<vector>
  7. #include<algorithm>
  8. using namespace std;
  9. const int maxn=30,maxm=300,K=10,A=7,B=3,C=4,P=10007,D=35;
  10. int a[maxm][2],co[maxn],f[maxn],tf[maxn],n,m,cot[maxn];
  11. void graph_hash()
  12. {
  13. int q,w,e;
  14. for(int i=1;i<=n;i++)
  15. {
  16. for( q=1;q<=n;q++)f[q]=1;
  17. for(int z=0;z<K;z++)
  18. {
  19. memcpy(tf,f,sizeof(f));
  20. for(q=1;q<=n;q++)f[q]*=A;
  21. for(q=0;q<m;q++)
  22. {
  23. f[a[q][0]]+=tf[a[q][1]]*B;
  24. f[a[q][1]]+=tf[a[q][0]]*C;
  25. }
  26. f[i]+=D;
  27. for(q=1;q<=n;q++)f[q]%=P;
  28. }
  29. co[i]=f[i];
  30. }
  31. sort(co+1,co+1+n);
  32. }
  33. int main()
  34. {
  35. int kt;scanf("%d",&kt);
  36. for(int ii=0;ii<kt;ii++)
  37. {
  38. scanf("%d%d",&n,&m);
  39. for(int i=0;i<m;i++)
  40. {
  41. scanf("%d%d",&a[i][0],&a[i][1]);
  42. a[i+m][0]=a[i][1];
  43. a[i+m][1]=a[i][0];
  44. }
  45. m=m*2;
  46. graph_hash();
  47. memcpy(cot,co,sizeof(co));
  48. m=m/2;
  49. for(int i=0;i<m;i++)
  50. {
  51. scanf("%d%d",&a[i][0],&a[i][1]);
  52. a[i+m][0]=a[i][1];
  53. a[i+m][1]=a[i][0];
  54. }
  55. m=m*2;
  56. graph_hash();
  57. bool ans=true;
  58. for(int i=1;i<=n;i++)
  59. {
  60. if(cot[i]!=co[i]){ans=false;break;}
  61. }
  62. if(ans==false){printf("different\n");}
  63. else printf("same\n");
  64. }
  65. return 0;
  66. }

  

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. Python3基础 用 函数递归求解 一个数字的阶乘

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  2. chrome的功能Copy as cURL

    https://segmentfault.com/q/1010000002508961

  3. spring整合mybatis,springMVC的0配置文件方式

    0配置文件的形式主要是采用spring3.0提供的@configuration注解和spring容器在启动的时候会加载实现了WebApplicationInitializer的类,并调用其onStar ...

  4. AFNetWorking 之 网络请求的基本知识

    NSString *urlStr = @"http://api.openweathermap.org/data/2.5/forecast/daily"; AFHTTPRequest ...

  5. 添加Action View

    ActionBar上除了可以显示普通的Action Item之外,还可以显示普通的UI组件.为了在ActionBar上添加ActionView,可以使用如下两种方式. 定义ActionItem时使用a ...

  6. Android项目中打jar包 和 使用

    第一步,把普通的android project设置成库项目 库项目也是一个标准的android项目,因此你先创建一个普通的android项目. 这个项目可以起任何的名称,任何的报名,设置其他需要设置的 ...

  7. C++实现具有基本功能的智能指针

    C++中的智能指针实际上是代理模式与RAII的结合. 自定义unique_ptr,主要是release()和reset().代码如下. #include <iostream> using ...

  8. Spring context:component-scan代替context:annotation-config

    Spring context:component-scan代替context:annotation-config XML: <?xml version="1.0" encod ...

  9. java_JDBC(4)

    一.Statement import java.sql.*; public class TestJDBC { public static void main(String[] args) { Conn ...

  10. iOS RunTime你知道了总得用一下

    说点题外话: 我刚来现在这家公司的时候,老板让我下载一个脉脉,上去找找自己的同行,多认识些同行.其实初衷的好的,但最近这两天我把它卸载了,不为别的,负能量太多!iOS这行自从2016就没景气过,在这行 ...