传送门
想了半小时,没什么思路。。
看了题解,是个叫做树分块的奇奇怪怪的操作。。
题解
树分块的研究
#include <cstdio>#include <cstring>#define N 2001int n, b, size, cnt, tot;int head[N], to[N], nex[N], belong[N], s[N], root[N];bool vis[N];inline void add(int x, int y)inline void dfs(int u)}}s[++size] = u;}int main()dfs(1);while(size) belong[s[size]] = tot;printf("%d\n", tot);for(i = 1; i <= n; i++) printf("%d ", belong[i]);puts("");for(i = 1; i <= tot; i++) printf("%d ", root[i]);return 0;}
上一篇:[luoguP3172] [CQOI2015]选数(递推+容斥原理)
下一篇:[luoguP1415] 拆分数列(DP)
分块









