样例迷,没过

交了30pts

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
}
#include <climits>
const int N = 1003;
const int MOD = 9999991; #define int long long
struct Edge{
int nxt, pre;
}e[N];
int head[N], cntEdge;
inline void add(int u, int v) {
e[++cntEdge] = (Edge){ head[u], v}, head[u] = cntEdge;
} int prime[1013], primeIndex;
bool vis[8007];
inline void EularPhi(int n) {
R(i,2,n){
if(!vis[i]) prime[++primeIndex] = i;
for(register int j = 1; j <= primeIndex && i * prime[j] <= n; ++j){
vis[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
}
}
} int siz[N]; int f[N], g[N], fa[N];
inline void DFS(int u, int father){
siz[u] = 1;
f[u] = 1;
fa[u] = father;
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(v == father) continue;
DFS(v, u);
siz[u] += siz[v];
f[u] = (f[u] + f[v] * prime[siz[v]] % MOD + MOD) % MOD;
}
} namespace HASH{ struct Node{
int nxt, pre, w;
}e[N * N];
int head[MOD + 3], cntHash; struct Hash{ inline void Insert(int x, int id){
int u = x % MOD;
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(v == x){
return;
}
}
e[++cntHash] = (Node){ head[u], x, id}, head[u] = cntHash;
}
inline int Query(int x){
int u = x % MOD;
for(register int i = head[u]; i; i= e[i].nxt){
int v = e[i].pre;
if(v == x){
return e[i].w;
}
}
return 0;
} }H; } #undef int
int main(){
#define int long long
EularPhi(8000); int n, m;
io >> m;
R(id,1,m){ cntEdge = 0;
Fill(head, 0); io >> n;
R(i,1,n){
int fa;
io >> fa;
add(i, fa);
add(fa, i);
} DFS(0, 0); int sum = LLONG_MAX;
R(i,0,n){
DFS(i, i);
sum = Min(sum, f[i]);
} HASH::H.Insert(sum, id); printf("%lld\n", HASH::H.Query(sum));
} return 0;
}

{{uploading-image-151875.png(uploading...)}}

BZOJ4337 树的同构 (树哈希)(未完成)的更多相关文章

  1. bzoj4337: BJOI2015 树的同构 树哈希判同构

    题目链接 bzoj4337: BJOI2015 树的同构 题解 树哈希的一种方法 对于每各节点的哈希值为hash[x] = hash[sonk[x]] * p[k]; p为素数表 代码 #includ ...

  2. BZOJ4337:[BJOI2015]树的同构(树hash)

    Description 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如 ...

  3. [BZOJ4337][BJOI2015]树的同构(树的最小表示法)

    4337: BJOI2015 树的同构 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1023  Solved: 436[Submit][Status ...

  4. 【BZOJ4474】isomorphism(树的同构,哈希)

    题意:一个无向树的度数为 2的结点称为假结点,其它结点称为真结点.一个无向树的简化树其结点由原树的全体真结点组成,两个真结点之间有边当且仅当它们在原树中有边,或者在原树中有一条联结这两个结点的路,其中 ...

  5. BZOJ 4337: BJOI2015 树的同构 树hash

    4337: BJOI2015 树的同构 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4337 Description 树是一种很常见的数 ...

  6. BZOJ.4337.[BJOI2015]树的同构(树哈希)

    BZOJ 洛谷 \(Description\) 给定\(n\)棵无根树.对每棵树,输出与它同构的树的最小编号. \(n及每棵树的点数\leq 50\). \(Solution\) 对于一棵无根树,它的 ...

  7. [BJOI2015]树的同构 && 树哈希教程

    题目链接 有根树的哈希 离散数学中对树哈希的描述在这里.大家可以看看. 判断有根树是否同构,可以考虑将有根树编码.而编码过程中,要求保留树形态的特征,同时忽略子树顺序的不同.先来看一看这个方法: 不妨 ...

  8. 【BZOJ4337】树的同构(树同构,哈希)

    题意: 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如果能够把树T1T ...

  9. bzoj4337树的同构

    树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如果能够把树T1的所有点重 ...

随机推荐

  1. redis+lua实现脚本一键查询

    场景 经常需要查redis某个key的值,需要执行三条命令才能查到 redis-cli,启动redis select num,选择db get key,查询语句 需要执行三条命令才能实现某个key的查 ...

  2. 商户编号[Merchant Id]是什么

    1. Merchant Id是什么 2. Merchant Id 是有哪几个部分构成的 2.1 收单机构代码 2.2 商户地区代码 2.3 Merchant Category Code(MCC) 本文 ...

  3. 华为云发布桌面IDE-CodeArts

    摘要:华为伙伴暨开发者大会2022,发布华为云桌面IDE-CodeArts. 本文分享自华为云社区<华为云发布桌面IDE-CodeArts,让连接更简单.编码更智能>,作者: Huawei ...

  4. SAP 时区转换

    DATA:l_tzone TYPE tzonref-tzone.   "TIME ZONE    DATA:l_timesp TYPE tzonref-tstamps."TIME  ...

  5. 03 转换css元素的类别

    03 转换css元素的类别 通过设置display属性 属性 作用 block 块级 inline 行内 inline-block 行内块级 接来下 就跟着小demo来学习吧! 不懂可以看看!!!什么 ...

  6. Python基础知识+题目练习,我不信你能做出这道题

    函数式编程 高阶函数 Python学习交流Q群:660193417#### map(func, *iterable) def fn(x, y, z): pass map(fn, range(10), ...

  7. 抓包整理外篇——————autoResponder、composer 、statistics [ 三]

    前言 经过了前文的介绍的部分已经能够为自己抓包提供一个舒适的环境了,但是舒服的拿到我们的包后,可能有些需求还是难以搞定,fiddler 提供了我们一些其他模块,让我们工作轻松,请往下看. 正文 aut ...

  8. Pytorch从0开始实现YOLO V3指南 part3——实现网络前向传播

    本节翻译自:https://blog.paperspace.com/how-to-implement-a-yolo-v3-object-detector-from-scratch-in-pytorch ...

  9. PoweJob高级特性-MapReduce完整示例

    由于网上搜索 PowerJob MapReduce 都是设计原理,demo也展示个空壳子,没有演示Map到Reduce结果怎么传递,对于没有MR开发经验的人来说并没有什么帮助,所以这里写了一个有完整计 ...

  10. 等待唤醒机制代码实现_包子类&包子铺类和等待唤醒机制代码实现_吃货类&测试类

    资源类:包子类 设置包子的属性 皮 陷 包子的状态:有 true 没有 false public class BaoZi { //皮 String pi; //陷 String xian; //包子的 ...