题目链接 dsu on tree详见这. \(Description\) 给定一棵树.求以每个点为根的子树中,出现次数最多的颜色的和. \(Solution\) dsu on tree模板题. 用\(sum[i]\)表示出现次数为\(i\)的颜色的和,\(cnt[i]\)表示出现次数为\(i\)的颜色有多少个(其实用个\(Max\)表示当前最多的次数,和每种颜色出现次数\(tm[i]\)就好了),然后..就这样了.. 可以用DFS序代替DFS减少一些常数. 再写一遍dsu on tree大体过程…
With $Dsu \ on \ tree$ we can answer queries of this type: How many vertices in the subtree of vertex $v$ has some property in $O (n \log n)$ time (for all of the queries)? 这题写的是轻重儿子(重链剖分)版本的 $Dsu \ on \ tree$ 具体流程如下: 每次先递归计算轻儿子,再单独递归重儿子,计算完后轻儿子的一些信息…
[题目]E. Lomsat gelral [题意]给定n个点的树,1为根,每个点有一种颜色ci,一种颜色占领一棵子树当且仅当子树内没有颜色的出现次数超过它,求n个答案——每棵子树的占领颜色的编号和Σci(一棵子树可能有多种占领颜色).1<=n,ci<=10^5. [算法]dsu on tree [题解]入门题,讲一下dsu on tree算法. 一.dsu on tree的适用范围:①子树询问,②支持数组上的快速信息加,③不带修.(注意不需要支持信息删除,只需要能清空信息) 如果写暴力的时候,…
题意 题目链接 给出一个树,求出每个节点的子树中出现次数最多的颜色的编号和 Sol dsu on tree的裸题. 一会儿好好总结总结qwq #include<bits/stdc++.h> #define LL long long using namespace std; ; inline int read() { , f = ; ; c = getchar();} + c - ', c = getchar(); return x * f; } int N, col[MAXN], son[MA…
题目链接 Lomsat gelral 占坑……等深入理解了再来补题解…… #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) typedef long long LL; const int N = 600010; int n; int cc[N], col[N], sz[N], son[N]; LL ans[N]; vector <int&g…
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it'…
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it'…