我是在neuqvj上交的这题:http://vj.acmclub.cn/problem/viewProblem.action?id=17848

本来是挺容易的树同构题,可是节点数比较多,愣是把普通hash卡掉了(出题人麻烦您过来一下)

只能用map映射一下,给每个状态一个标号,而状态的表示是它两个儿子的标号。

#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 110001
#define ll long long
#define fi first
#define se second
using namespace std; int read_p,read_ca,read_f;
inline int read(){
read_p=;read_ca=getchar();read_f=;
while(read_ca<''||read_ca>'') read_f=read_ca=='-'?-:read_f,read_ca=getchar();
while(read_ca>=''&&read_ca<='') read_p=read_p*+read_ca-,read_ca=getchar();
return read_p*read_f;
}
const int HA=1e6+;
int T,n,m,ha[MN],a,b,L[MN],R[MN],nm=,mmh[][MN];
ll MMH;
map<pair<int,int>,int>mp;
int dfs(int x,int mmh[]){
int MMH;
pair<int,int> now=make_pair(L[x]==-?:dfs(L[x],mmh),R[x]==-?:dfs(R[x],mmh));
if (mp.find(now)==mp.end()) MMH=mp[now]=++nm;else MMH=mp[now];
mmh[MMH]++;
return MMH;
}
inline void work(int n,int mmh[]){
for (int i=;i<=n;i++) L[i]=read(),R[i]=read();
dfs(,mmh);
}
int main(){
T=read();
for (int i=;i<MN;i++) ha[i]=rand()%HA;
while (T--){
nm=;mp.clear();
memset(mmh,,sizeof(mmh));
n=read();m=read();MMH=;
work(n,mmh[]);
work(m,mmh[]);
for (int i=;i<=nm;i++) MMH+=1LL*mmh[][i]*mmh[][i];
printf("%lld\n",MMH);
}
}

C++ 190 8608

ZOJ3602:Count the Trees的更多相关文章

  1. zjuoj 3602 Count the Trees

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3602 Count the Trees Time Limit: 2 Seco ...

  2. Count the Trees[HDU1131]

    Count the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)

     Count the Trees  Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...

  4. TZOJ 4292 Count the Trees(树hash)

    描述 A binary tree is a tree data structure in which each node has at most two child nodes, usually di ...

  5. HDU 1131 Count the Trees 大数计算

    题目是说给出一个数字,然后以1到这个数为序号当做二叉树的结点,问总共有几种组成二叉树的方式.这个题就是用卡特兰数算出个数,然后因为有编号,不同的编号对应不同的方式,所以结果是卡特兰数乘这个数的阶乘种方 ...

  6. UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)

    题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...

  7. uva 10007 Count the Trees

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. HDU 1131 Count the Trees

    卡特兰数再乘上n的阶乘 #include<iostream> #include<cstdio> using namespace std; #define base 10000 ...

  9. 2012-2014 三年浙江 acm 省赛 题目 分类

    The 9th Zhejiang Provincial Collegiate Programming Contest A    Taxi Fare    25.57% (166/649)     (水 ...

随机推荐

  1. 【java】反射简单示例

    package 反射; public class Test反射 { public static void main(String[] args) { System.out.println(Runtim ...

  2. 关于html,css,js三者的加载顺序问题

    <head lang="en"> <meta charset="utf-8"> <title></title> ...

  3. Mac下nvm管理node.js版本问题

    本篇文章主要是针对已经安装了node.js和nvm管理工具小伙伴遇到的问题. 管理工具有两个,一个是nvm,还有一个是nnvm的好处就是可以管理多个node版本,而且可以切换想要的版本,可以安装一个稳 ...

  4. Docker安装入门 -- 应用镜像

    Docker安装入门 -- 应用镜像 WordPress  1.docker build -t csphere/wordpress:4.2 .  2.docker run -d -p 80:80 -- ...

  5. su 和 sudo 命令的区别-转载

    link 一. 使用 su 命令临时切换用户身份                   1.su 的适用条件和威力   su命令就是切换用户的工具,怎么理解呢?比如我们以普通用户beinan登录的,但要 ...

  6. python学习中的一些“坑”

    一.交互列表元素时,需要注意的坑. 例如: array=[4,5,9,8,10,8,4,0,3,4]  最大的值与第一个元素交换,最小的值与最后一个元素交换 # -*- coding: UTF-8 - ...

  7. js获取字符串最后一位方法

    方法一:运用String对象下的charAt方法 charAt() 方法可返回指定位置的字符. str.charAt(str.length – 1) 请注意,JavaScript 并没有一种有别于字符 ...

  8. Xamarin.Android 引导页

    http://blog.csdn.net/qq1326702940/article/details/78665588 https://www.cnblogs.com/catcher1994/p/555 ...

  9. 用 HAproxy 搭建 RabbitMQ 集群

    构建参考: [ Rabbitmq cluster setup with HAproxy ] [ python demo ] RabbitMQ Cluster 遇到的问题 python pika 作为c ...

  10. Excel数据导入至Dataset中

    public static DataSet ExcelToDataSet(string ppfilenameurl,string pptable) { string strConn = "P ...