D. Alyona and a tree time limit per test  2 seconds memory limit per test  256 megabytes input  standard input output  standard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive in…
题目链接 Alyona and a tree 比较考验我思维的一道好题. 首先,做一遍DFS预处理出$t[i][j]$和$d[i][j]$.$t[i][j]$表示从第$i$个节点到离他第$2^{j}$近的祖先,$d[i][j]$表示从$i$开始到$t[i][j]$的路径上的路径权值总和. 在第一次DFS的同时,对节点$x$进行定位(结果为$dist(x, y)<=a(y)$)的离$x$最远的$x$的某个祖先,然后进行$O(1)$的差分. 第一次DFS完成后,做第二次DFS统计答案(统计差分后的结…
<题目链接> 题目大意: 给定一颗带权树,树的根是1,树上每个点都有点权,并且还有边权.现在给出“控制”的定义:对一个点u,设v为其子树上的节点,且$dis(u,v)≤val[v]$,则称u控制v.求出每个点控制的点数. 解题分析: 处理出所有点到根的距离$dist$,然后任意两点之间的距离为$dist[v]-dist[u]$($v$为$u$的子树中的节点).因为在每条链上,$dist$由根向子树深搜的过程中都是递增的,所以可以用二分快速找到能够控制当前节点的$dep$最浅的父亲节点,然后利用…
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on. The girl noticed that some of the tree…
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive int…
Alyona and the Tree 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/C Description Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every v…
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positiv…
题目链接:http://codeforces.com/problemset/problem/682/C 题目大意:取树上任意一个点v,若点v的子树中有一个点u使得dist(v,u)>a[u]那么称节点v是伤心的.给你一个根为1的树,每个节点有一个权值a[i],每条边也有一个权值w,现在让你删最少的结点,使得树上不存在伤心的点.解题思路:删除最少的点,我们可以反一下,变成找最多的点,使得这些点不伤心.只要对这棵树进行DFS,同时记录路径长度dis,当到达某点u时,若dis>a[u],那么要将u及…
题目大概说给一棵点有权.边也有权的树.一个结点v不高兴当且仅当存在一个其子树上的结点u,使得v到u路径上的边权和大于u的权值.现在要不断地删除叶子结点使得所有结点都高兴,问最少删几个叶子结点. 一开始题目看错了,以为说的是v到u路径上的边权和小于v的权值,然后想出了个解法:从根开始DFS,找高兴的结点,递归过程中在set插入各个祖先结权值,递归返回时从set中删除,而如果set里面最小的元素小于当前结点的路径和那么这个结点就不能要直接return,另外还用到一个简单的数学原理——两个数同时加上相…
题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被删去的点数. 思路:1为根节点,从1开始DFS遍历,记录距离dis为到祖宗节点的最大距离. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+5; int a[N],num[N],a…