【codeforces 348B】Apple Tree】的更多相关文章

[题目链接]:http://codeforces.com/problemset/problem/348/B [题意] 给你一棵树; 叶子节点有权值; 对于非叶子节点: 它的权值是以这个节点为根的子树上的叶子节点的权值的和; 定义一棵树是平衡的,当且仅当,每个节点的所有直系儿子的权值都相等; 问你要使得这棵树平衡,最少需要删除掉多少叶子节点上的权值; [题解] 在第一个dfs里面求出d[i]和s[i]; 设d[i]表示以i为根的子树要平衡的话最少需要多少权值(注意这里不是说最少要删去多少权值,而是…
[POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8981   Accepted: 2990 Description Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each…
Apple Tree Description Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amount of apples. Wshxzt starts her happy trip at one node. She can eat up all the apple…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. I…
[题目链接]:http://codeforces.com/contest/723/problem/F [题意] 给你一张图; 让你选择n-1条边; 使得这张图成为一颗树(生成树); 同时s的度数不超过ds且t的度数不超过dt [题解] 先把s和t隔离开; 考虑其他点形成的若干个联通块; 因为一开始的图是联通的; 所以,那些不同的联通块,肯定是通过s或通过t而联通的; 这样就只要考虑每个联通块和s.t的联通性了; 对于只能和s或t之中的一个相连的块; 直接连一条边到s或t就好,然后ds-=1或是d…
[poj2486]Apple Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10800   Accepted: 3629 Description Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node ha…
Description 程序员 ZS 有一棵树,它可以表示为 \(n\) 个顶点的无向连通图,顶点编号从 \(0\) 到 \(n-1\),它们之间有 \(n-1\) 条边.每条边上都有一个非零的数字. 一天,程序员 ZS 无聊,他决定研究一下这棵树的一些特性.他选择了一个十进制正整数 \(M\),\(\gcd(M,10)=1\). 对于一对有序的不同的顶点 \((u, v)\),他沿着从顶点 \(u\) 到顶点 \(v\)的最短路径,按经过顺序写下他在路径上遇到的所有数字(从左往右写),如果得到…
http://codeforces.com/contest/348/problem/B 题意:给一棵树,每个叶子结点有w[i]个苹果,每个子树的苹果数量为该子树所有叶子结点苹果数量之和,要使得每个结点的各个子树苹果数量相等,求至少需要拿走的苹果数量. 思路:一开始以为只要使得所有子树之和相同就行了. void dfs(int u, int fa) { , mi = INF; for(int i = head[u]; ~i; i = edge[i].nxt) { int v = edge[i].v…
有n个节点以1为根节点的树,给你树的边关系u-v,一开始每个节点都有一个苹果,接下来有两种操作,C x改变节点x的苹果状态,Q x查询x为根的树的所有苹果个数.   求出树的dfs序,st[i]保存i的进入时间戳,ed[i]保存i的退出时间戳,则st[i]到ed[i]就是子树节点的对应时间戳. 每个节点打了两次时间戳,其中ed[i]会等于最后访问的一个子节点的st[i]. 于是用线段树/树状数组的单点修改和区间求和就可以解决. #include<cstdio> #define N 100005…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…