样例迷,没过

交了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...)}}

最新文章

  1. 深入理解Memcache原理 [转]
  2. java lambda表达式学习笔记
  3. ZOJ 1113 u Calculate e
  4. RGBa颜色 css3的Alpha通道支持
  5. String、StringBuffer和StringBuilder的区别
  6. WordPress /wp-admin/includes/post.php user_ID 参数操作权限提升漏洞
  7. 【剑指offer】面试题37:两个链表的第一个公共结点
  8. [置顶] Java中发邮件的6种方法
  9. 执行update操作的话,就会报“Connection is read-only. Queries leading to data modification are not allowed”的异常。
  10. 201521123020《java程序设计》第十周学习总结
  11. shell中数组讲解
  12. BS架构和CS架构的区别
  13. FreeBSD 12.0 版发布
  14. WEB前端技巧之JQuery为动态添加的元素绑定事件.md
  15. [Pytorch]深度模型的显存计算以及优化
  16. 2018.10.18 bzoj4105: [Thu Summer Camp 2015]平方运算(线段树)
  17. 【代码笔记】iOS-自定义选择框
  18. “4K云字库”基本框架图
  19. 2018.12.25 SOW
  20. 大数据学习--day13(字符串String--源码分析--JVM内存分析)

热门文章

  1. Java 接口返回值集合防止空指针
  2. mybatis中二级缓存整合ehcache实现分布式缓存
  3. 内网穿透frp教程 windows远程桌面连接
  4. 免费CDN:jsDelivr+Github 使用方法
  5. 硬件开发笔记(四):硬件开发基本流程,制作一个USB转RS232的模块(三):设计原理图
  6. VSCode 安装以及初步使用教程
  7. Java常用类-包装类
  8. 记安装AWVS14过程踩的坑
  9. SAP BOM 读取
  10. 记一次beego通过go get命令后找不到bee.exe的坑