CF1039D You Are Given a Tree LG传送门 根号分治好题. 这题可以整体二分,但我太菜了,不会. 根号分治怎么考虑呢?先想想\(n^2\)暴力吧.对于每一个要求的\(k\),一遍dfs直接贪心,能拼成链就直接拼,正确性不用我证明吧. 考虑对于\(k \le \sqrt n\),直接按照暴力去做,复杂度\(O(n \sqrt n)\):对于\(k\)从\(\sqrt n+1\)到\(n\)的所有情况,我们发现答案只会在\(\sqrt n\)到\(0\)之间取值(\(k>…
xor There is a tree with nn nodes. For each node, there is an integer value a_iai, (1 \le a_i \le 1,000,000,0001≤ai≤1,000,000,000 for 1 \le i \le n1≤i≤n). There is qq queries which are described as follow: Assume the value on the path from node…
[CF1039D]You Are Given a Tree 题目大意: 给定一棵\(n(n\le10^5)\)个节点的树.对于每一个正整数\(k(1\le k\le n)\),求最多能找出多少条包含\(k\)个点的路径,使得这些路径没有公共点. 思路: 答案只可能有大约\(2\sqrt n\)种,对于每一种答案二分其对应的\(k\)的范围,每次自底向上贪心地选择路径.卡卡常就可以过了. 时间复杂度\(\mathcal O(n\sqrt n\log n)\). 源代码: #include<cmat…