Codeforces 1076 E - Vasya and a Tree】的更多相关文章

E - Vasya and a Tree 思路: dfs动态维护关于深度树状数组 返回时将当前节点的所有操作删除就能保证每次访问这个节点时只进行过根节点到当前节点这条路径上的操作 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #de…
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个点,初始时候每个点权值都为0,m次修改,对v的叶子节点且距离小于d的都加上x 也就是v以下d层包括v自身都加上x 问最后每个点的权值 现在一想 用线段树来维护就是很自然的事了 但是要维护什么值呢 维护的就是某个深度上增加的值 先更新 后回溯取消更新 详见代码注释 #include <cstdio>…
题面 Vasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it. Let d(i,j) be the distance between vertices i and j, i.e. number of edges in the shortest path from i to j. Also, let's denote k-subtree of…
CodeForces - 1076E Problem Description: Vasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it. Let d(i,j) be the distance between vertices i and j, i.e. number of edges in the shortest path from i…
题目链接:codeforces 1065F Up and Down the Tree 题意:给出一棵树的节点数\(n\)以及一次移动的最大距离\(k\),现在有一个标记在根节点1处,每一次可以进行一下的两个操作之一: 1.将标记移动至当前节点的子树中的某一个叶子 2.将当前标记向上移,向上移的距离不得超过\(k\) 求最多可以访问到多少个叶子结点 分析:一看就知道应该用树形dp去维护它 我们记\(dp[u]\)表示以\(u\)为根节点的子树中最多可以访问多少个叶子结点 \(dp[u]\)由两部分…
题目链接:传送门 题目: E. Vasya and a Tree time limit per test seconds memory limit per test megabytes input standard input output standard output Vasya has a tree consisting of n vertices with root . At first all vertices has written on it. Let d(i,j) be the…
Vasya has a tree consisting of n n vertices with root in vertex 1 1 . At first all vertices has 0 0 written on it. Let d(i,j) d(i,j) be the distance between vertices i i and j j , i.e. number of edges in the shortest path from i i to j j . Also, let'…
Codeforces 914H Ember and Storm's Tree Game 题目链接 ORZ佬 果然出了一套自闭题 这题让你算出第一个人有必胜策略的方案数 然后我们就发现必胜的条件就是树上的每条路径都是单调或者单峰的 所以我们考虑DP一个每条路径都是单调或单峰的树出来 所以考虑DPf[i][j]" role="presentation" style="position: relative;">f[i][j]f[i][j]表示大小是i的子树…
Vasya and a Tree 题意: 给定一棵树,对树有3e5的操作,每次操作为,把树上某个节点的不超过d的子节点都加上值x; 思路: 多开一个vector记录每个点上的操作.dfs这颗树,同时以深度开一个树状数组,踩到u节点的时候,给数组add(deep, x); add(min(maxn,deep + op[u][i].fi + 1), - op[u][i].se); 搜索下去,反回前得到这个节点的答案,并消去这个点的影响. //#pragma GCC optimize(3) //#pr…
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/problem/F Solution 设\(v_i\)表示第\(i\)个点的果子数,设\(b_i=v_i-\sum_{x\in son}v_x\),显然依题意要满足\(b_i\geqslant 0\). 根据差分的性质我们可以得到\(\sum b_i=x\). 假设我们硬点树上剩下了\(m\)个点,则…