Pku2054 Color a Tree】的更多相关文章

有一个N个结点的有根树,1是这个树的根.现在要对这N个结点依次进行染色,每个结点染色要花费1个单位的时候,同时要满足一个结点仅在其父亲被染色后才可被染色,每个结点有个权值Ci,如果我们在第Ti时间对i号结点染色,则付出总代价为Sigma(Ti*Ci),1<=i<=N.现在给出这个树和每个点的权值,请构造一种染色顺序,使得总代价最小.N<=1000 5 1//5个点1 2 1 2 4 //5个点的权值1 21 32 43 50 0//整个测试结束Sample Output33 Sol:一个…
贪心....                    Color a Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6647   Accepted: 2249 Description Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is single…
Color a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 828    Accepted Submission(s): 272 Problem DescriptionBob is very interested in the data structure of a tree. A tree is a directed gr…
/* 十分巧妙的二分 题意选最少的点涂色 使得满足输入信息: 1 x的子树涂色数不少于y 2 x的子树外面涂色数不少于y 我们若是把2转化到子树内最多涂色多少 就可以维护这个最小和最大 如果我们二分出了答案 就可以完成转化 转化后也恰好可以判断二分是否合法 */ #include<cstdio> #include<cstring> #include<iostream> #define maxn 100010 using namespace std; int T,n,m,…
题干 Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is singled out, called the "root" of the tree, and there is a unique path from the root to each of the other nodes. Bob intends to colo…
Color a Tree 题目链接 好不可做?可以尝试一下DP贪心网络流.DP 似乎没法做,网络流也不太行,所以试一下贪心. 考虑全局中最大权值的那个点,如果它没父亲,那么一定会先选它:否则,选完它父亲就一定先选它.于是我们可以把它缩成一个点. 但是我们并不知道缩点后的权值是多少,这样就没法继续缩下去.我们考虑一对被缩点的父子 \(x,y\),以及全局中的另一个点 \(a\),什么时候会先选 \(a\),什么时候先选 \(x,y\).如果先选 \(x,y\),那么就有 \(x + 2y + 3a…
传送门 看一眼感觉 $dp$,发现状态没法维护 考虑贪心,然后就想了两个错的贪心... 正解好神啊 首先如果权值最大的点能够一步染色那么肯定要染它 意思就是,一旦父节点被染色那么它就要接着被染色 那么把它们父子两合并成一个新的点,其他节点根据原来的边也连上来 考虑新的点的权值要怎么搞,现在既然这个节点包含了两个点,那么把它染色要两个单位时间,而染其他点只要 $1$ 单位时间 此时染它对整颗树产生的额外的代价为 $2$ 乘其他节点权值和,把其他点 $x$ 染色额外代价为 $1$ 乘其他节点 (非…
Bob intends to color the nodes of a tree with a pen. The tree consists of NN nodes. These nodes are numbered 1,2,...,N1,2,...,N. The root of the tree is node 11. The initial color of each node is white. Bob can use one unit energy to color one node i…
Bob intends to color the nodes of a tree with a pen. The tree consists of NN nodes. These nodes are numbered 1,2,...,N1,2,...,N. The root of the tree is node 11. The initial color of each node is white. Bob can use one unit energy to color one node i…
这道题细节真的非常多 首先能够想到a和b的最优策略一定是沿着a和b在树上的链走,走到某个点停止,然后再依次占据和这个点邻接的边 所以,解决这道题的过程例如以下: 预处理阶段: step 1:取随意一个点为根节点.找出父子关系而且对这个树进行dp.求出从某个节点出发往下所包括的全部边的权值总和  复杂度O(n) step 2:从tree dp 的结果中计算对于某个节点.从某条边出发所包括的边的综合.而且对其从大到小进行排序 复杂度O(n*logn) step 3:dfs求出这颗树的欧拉回路,以及每…