BZOJ4337 树的同构 (树哈希)(未完成)
样例迷,没过
交了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 树的同构 (树哈希)(未完成)的更多相关文章
- bzoj4337: BJOI2015 树的同构 树哈希判同构
题目链接 bzoj4337: BJOI2015 树的同构 题解 树哈希的一种方法 对于每各节点的哈希值为hash[x] = hash[sonk[x]] * p[k]; p为素数表 代码 #includ ...
- BZOJ4337:[BJOI2015]树的同构(树hash)
Description 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如 ...
- [BZOJ4337][BJOI2015]树的同构(树的最小表示法)
4337: BJOI2015 树的同构 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1023 Solved: 436[Submit][Status ...
- 【BZOJ4474】isomorphism(树的同构,哈希)
题意:一个无向树的度数为 2的结点称为假结点,其它结点称为真结点.一个无向树的简化树其结点由原树的全体真结点组成,两个真结点之间有边当且仅当它们在原树中有边,或者在原树中有一条联结这两个结点的路,其中 ...
- BZOJ 4337: BJOI2015 树的同构 树hash
4337: BJOI2015 树的同构 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4337 Description 树是一种很常见的数 ...
- BZOJ.4337.[BJOI2015]树的同构(树哈希)
BZOJ 洛谷 \(Description\) 给定\(n\)棵无根树.对每棵树,输出与它同构的树的最小编号. \(n及每棵树的点数\leq 50\). \(Solution\) 对于一棵无根树,它的 ...
- [BJOI2015]树的同构 && 树哈希教程
题目链接 有根树的哈希 离散数学中对树哈希的描述在这里.大家可以看看. 判断有根树是否同构,可以考虑将有根树编码.而编码过程中,要求保留树形态的特征,同时忽略子树顺序的不同.先来看一看这个方法: 不妨 ...
- 【BZOJ4337】树的同构(树同构,哈希)
题意: 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如果能够把树T1T ...
- bzoj4337树的同构
树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树就成为有根树. 对于两个树T1和T2,如果能够把树T1的所有点重 ...
随机推荐
- Linux版 MySql57安装教程
这里介绍的是CentOS7.4安装mysql57的教程 创建MySQL文件包 使用mkdir -p 文件夹路径创建以下目录: 文件夹路径 用途 /usr/local/mysql MySQL安装路径 / ...
- 如何在 Mac 和虚拟机上安装 macOS Big Sur、Monterey 和 Ventura
请访问原文链接:https://sysin.org/blog/how-to-install-macos/,查看最新版.原创作品,转载请保留出处. 作者主页:www.sysin.org 名词解释: 硬件 ...
- 2021.06.12【NOIP提高B组】模拟 总结
T1 题目大意:有 \(n\) 个点,到点 \(i\) 可以获得 \(A_i\) ,同时消耗 \(B_i\) 若当前价值小于 \(B_i\) 则不能到,问从 \(P\) 开始,任一点结束后的最大值. ...
- JS:object
object:对象 1.对象是拥有属性和方法的数据,也是一个变量,但值有多个,以key-value的形式. 2.对象有继承属性: 每当创建一个对象,对象里面就会有一个原型对象prototype,可以从 ...
- RPA供应链管制单修改机器人
背景:供应链环节中,研发物料时而因为市场缺货等原因无法采购,资材部需登入系统修改物料管制单. 操作流程:登录PDM系统中读取数据.登录ERP系统中更新数据. 人工操作:每日耗时3.5小时,出现一定比例 ...
- rhel7修改网卡名
备份eno16777736网卡配置,并复制出一个ifcfg-eth0 [root@rhel7 network-scripts]# cp ifcfg-eno16777736 ifcfg-eno16777 ...
- BigDecimal加减乘除及setScale的用法小结
Bigdecimal初始化: BigDecimal num = new BigDecimal(2.225667);//这种写法不允许,会造成精度损失. BigDecimal num = new Big ...
- typescript+webpack构建一个js库
依赖说明 入口文件 tsconfig配置 webpack配置文件 webpack入口文件配置 webpack为typescript和less文件配置各自的loader webpack的output配置 ...
- 强化学习-学习笔记5 | AlphaGo
本文不是论文阅读笔记,只是一个学习笔记,重在理解,在严谨程度上可能稍差. AlphaGo 论文指路: Mastering the game of Go with deep neural network ...
- Collection子接口:List接口
1. 存储的数据特点:存储序的.可重复的数据. 2. 常用方法:(记住)增:add(Object obj)删:remove(int index) / remove(Object obj)改:set(i ...