USACO Grass Planting】的更多相关文章

洛谷 P3038 [USACO11DEC]牧草种植Grass Planting 洛谷传送门 JDOJ 2282: USACO 2011 Dec Gold 3.Grass Planting JDOJ传送门 Description Problem 3: Grass Planting [Travis Hance, 2011] Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roa…
Grass Planting 题意 给出一棵树,树有边权.每次给出节点 (u, v) ,有两种操作:1. 把 u 到 v 路径上所有边的权值加 1.2. 查询 u 到 v 的权值之和. 分析 如果这些值不是在树上,而是在区间上,那么凭借线段树.树状数组可以很轻松的解决,但是在树上则不能直接操作. 树链剖分就是将树上的节点映射到区间上,从而实现区间操作. 学习树链剖分前需要掌握的知识点:线段树.LCA. 参考blog 认真读完这篇 blog ,跟着算法流程走一遍差不多就懂了. code #incl…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
Description Farmer John has N barren pastures connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on the roads betwe…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional roads, such that there is exactly one path between any two pastures. Bessie, a cow who loves her grazing time, often complains about how there is no grass on t…
题目大意: 有一棵结点个数为n的树,有m个操作,可以将一段路径上每条边的权值+1或询问某一个边的权值. 思路: 树链剖分+线段树. 轻重链划分本身比较简单,主要需要思考如何用线段树维护每条链. 当x,y不在同一条链上时,先处理深度大的链,对于每一个链,建立一棵动态开点的线段树,用一个数组len顺序记录每一条边在链中的编号,然后维护len[x]+1到len[top[x]]这一区间的权值即可. 处理轻边时,可以直接用一个数组保存它的权值. 因为轻重边肯定是交替的,因此每次循环都可以先维护一个重边,再…
54  种草约翰有 N 个牧场,编号为 1 到 N.它们之间有 N − 1 条道路,每条道路连接两个牧场.通过这些道路,所有牧场都是连通的.刚开始的时候,所有道路都是光秃秃的,没有青草.约翰会在一些道路上批量种草.每次开始种草的时候,约翰会选择一个牧场作为起点,一个牧场作为终点,找到从起点到终点的最短路径,在这条路径上所有的道路上分别种下一棵新的青草.贝西在监督约翰的工作,她迫不及待地想知道每条道路上已经有多少青草了.约翰的工作总是被贝西打断,他不胜其烦,所以请你来帮忙回答贝西的问题.约翰的工作…