Split The Tree】的更多相关文章

Split The Tree 时间限制: 1 Sec  内存限制: 128 MB提交: 46  解决: 11[提交] [状态] [讨论版] [命题人:admin] 题目描述 You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value wiWe define the weight of a tree as the number of different vertex value in the…
Split The Tree 时间限制: 1 Sec  内存限制: 128 MB 题目描述 You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value wiWe define the weight of a tree as the number of different vertex value in the tree.If we delete one edge in the tree, t…
树形DP. 用倍增处理出来每个点往上能延伸出去的最远路径,nlogn 对于每个节点,如果它能被后代使用过的点覆盖,就直接覆盖,这个点就不使用,否则就ans++,让传的Max改成dp[x] #include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; ; ],f[N],head[N],to[N<<],nxt[N<<…
Problem E. Split The Tree Problem Description You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value wi We define the weight of a tree as the number of different vertex value in the tree. If we delete one edge in the tree,…
https://codeforces.com/contest/1059/problem/E 题意 给出一棵树,每个点都有一个权值,要求你找出最少条链,保证每个点都属于一条链,而且每条链不超过L个点 和 每条链的权值和不超过S 题解 对于儿子来说,父亲节点只有一个,所以没有决策点.可以从下往上处理出,每个节点最远能爬到那个节点(过程就是倍增) 然后从下往上贪 (选择往上走的远的子节点) #include<bits/stdc++.h> #define ll long long #define pb…
题意 给定 \(n\) 个节点的树,点有点权 \(w\) ,划分成多条儿子到祖先的链,要求每条链点数不超过 \(L\) ,和不超过 \(S\),求最少划分成几条链. \(n\leq 10^5\) . 分析 贪心,从叶子节点开始向上合并,倍增计算出以一个节点为链底,能够最多到达哪个祖先 \({up}_u\). 每个节点合并和时候取每个子树的 \(up\) 最浅的那个,正确性显然. 总时间复杂度为 \(O(nlogn)\). 代码 #include<bits/stdc++.h> using nam…
题目:http://codeforces.com/problemset/problem/1059/E 用倍增可以在nlog内求出每个节点占用一个sequence 时最远可以向父节点延伸到的节点,对每个节点作为sequence 的最后一个元素向上延伸时,将节点的父节点属性合并(类似于并查集的操作), 存在优先队列里保证每次先操作dep最大的节点 #include<iostream> #include<cstdio> #include<cmath> #include<…
题意翻译 现有n个点组成一棵以1为根的有根树,第i个点的点权为wi,需将其分成若干条垂直路径使得每一个点当且仅当被一条垂直路径覆盖,同时,每条垂直路径长度不能超过L,点权和不能超过S,求最少需要几条垂直路径才能满足要求.特别地,无解输出-1. 一条垂直路径是一条包含v1, v2...vk的路径,使得vi(i>=2)是vi-1的父亲. 题解 话说莫不是树上的题目全都可以用倍增艹过去…… 首先,这个东西是可以贪心的,我们每一次一定是选取子树里能向上拓展最多的点与自己连成一条链 然后每一个节点最多能向…
B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are color…
CF462D Codeforces Round #263 (Div. 2) D Codeforces Round #263 (Div. 1) B B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman has a tree with n vertices. Some of t…