http://codeforces.com/problemset/problem/740/D 对于每一对<u, v>.设dis[u]表示root到点u的距离,那么dis<u去v>就是dis[v] - dis[u], 就是在它的儿子中找出有多少个v使得dis[v] - dis[u] <= a[v].然后,因为如果v确定了,那么dis[v]和a[v]就确定了. 所以把公式转换为dis[v] - a[v] <= dis[u]. 那么可以暴力枚举每一个u,然后在其儿子中找有多少…
题目描述: 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…
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edg…
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 integer,…
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the g…
题目链接: 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…
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…
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 integer,…
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/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 verte…
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 intege…
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted…
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统计答案(统计差分后的结…
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted…
题目链接: C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic r…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wr…
Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. 小灵注意到树上有一些节点不开心,所以她决定和它们一起玩. 如果节点 v 的子树中有一个节点 u 使得dist(v, u) > au ,那么节点 v 就会不开心.au 代表节点 u 上的数字,dist(v, u)代表连接节点 v 到节点 u 的所有边上的数字和,也就是两个节点的距离. 通过 1 条边连…
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted…
E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Description Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules: There are…
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the…
Easy version:Codeforces 题面传送门 & 洛谷题面传送门 Hard version:Codeforces 题面传送门 & 洛谷题面传送门 发现自己交互题烂得跟 sh*t 一样--于是不管三七二十一先来两道再说( 首先考虑最 trivial 的情况,也就是 \(k=1\) 和 \(k=n\) 两种情况,对于 \(k=1\) 你就 \(\mathcal O(n^2)\) 地检查一遍所有的 pair,具体来说我们枚举所有 \(i,j(i<j)\),然后依次询问 \(i…
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…
http://acm.hdu.edu.cn/showproblem.php?pid=6394 题意 给出一棵树,然后每个节点有一个权值,代表这个点可以往上面跳多远,问最少需要多少次可以跳出这颗树 分析 先dfs一次得到dfs序,然后按dfs序分块.倍增计算从某点跳x到哪个点,用cn保存它跳出这一块需要的次数,ne保存跳出这块会去的点.然后块内就暴力修改了.复杂度nsqrt(n); #include <iostream> #include <cstdio> #include <…
翻译 将下图中上面的二叉树转换为以下的形式.详细为每一个左孩子节点和右孩子节点互换位置. 原文 如上图 分析 每次关于树的题目出错都在于边界条件上--所以这次细致多想了一遍: void swapNode(TreeNode* tree) { if (tree == NULL || (tree->left == NULL && tree->right == NULL)) {} else if (tree->left == NULL && tree->ri…
1.markdown 用法及公式编写,这块就不再重复,已有很多官方平台的文档说明很完善 有道云markdown写作文档 在博客园中插入公式 markdown公式输入(特殊符号) markdown 特殊符号输入 2.一般做笔记喜欢在有道云写,因为有实时预览,写好后再copy到博客园中.这两个平台大部分markdown语法都相同,有一点需要留意: 有道云编辑公式时需要在公式前后用 来包起来,而博客园平台则不用,因此需要先将有道云写好的文章copy到notepad++中将 全都替换为空,再将其copy…
题目大概说给一棵点有权.边也有权的树.一个结点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…
这个题就是在dfs的过程中记录到根的前缀和,以及前缀和的最小值 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <stack> #include <queue> #include <algorithm> #include…
方法:从根节点开始广搜,如果遇到了应该删除的点,就再广搜删掉它的子树并标记,然后统计一下被标记的个数就是答案,所谓技巧就是从根节点开始搜索的时候,如果遇到了某个节点的距离<0,就让它是0,0可以消除负数效应,让后面的点重新参与正常删除操作,这个方法的正确性不难证明,可以自己画一下图.而且还有比较方便的方法就是,记录不被删除的点,然后n-他们就可以了. 代码如下: #include<iostream> #include<cstdio> #include<cstring&g…
二分+dfs序+前缀和+瞎几把yy #include "a.h" int n; aLL a; struct edge { int to, nx, w; } e[N << ]; arr fi; ; aLL sum, ans; aLL vec, up, down, res; ll tot = ; ll rs = ; inline void add(int u, int v, int w) { e[++ce] = edge{v, fi[u], w}; fi[u] = ce; }…