A Simple Problem On A Tree(树链剖分+线段树)

这是一篇关于如何使用树链剖分和线段树解决树上问题的博客,包括四种操作:修改、增加、乘法和求路径节点权重的三次方和。题目给出了一棵具有N个节点的树,每个节点有重量,并需要对树上的路径进行各种操作。线段树被用来高效地处理这些路径上的节点。博客提供了维护三次方和的策略,以及相关的参考链接。
摘要由CSDN通过智能技术生成

链接:https://ac.nowcoder.com/acm/problem/202310
来源:牛客网
 

题目描述

We have met so many problems on the tree, so today we will have a simple problem on a tree.
You are given a tree (an acyclic undirected connected graph) with N\mathbf{N}N nodes. The tree nodes are numbered from 1\mathbf{1}1 to N\mathbf{N}N. Each node has a weight Wi\mathbf{W_i}Wi​. We will have four kinds of operations on it and you should solve them efficiently. Wish you have fun!

输入描述:

The first line of the input gives the number of test case, T\mathbf{T}T (1≤T≤101 \leq \mathbf{T} \leq 101≤T≤10). T\mathbf{T}T test cases follow.
For each case, the first line contains only one integer N\mathbf{N}N.(1≤N≤100,0001 \leq \mathbf{N} \leq 100,0001≤N≤100,000) The next N−1\mathbf{N-1}N−1 lines each contains two integers x{x}x, y{y}y which means there is an edge between them. It also means we will give you one tree initially. 
The next line will contains N\mathbf{N}N integers which means the initial weight Wi\mathbf{W_i}Wi​ of each node. (0≤Wi≤1,000,000,0000 \leq \mathbf{W_i} \leq 1,000,000,0000≤Wi​≤1,000,000,000)

The next line will contains an integer Q\mathbf{Q}Q. (1≤Q≤10,0001 \leq \mathbf{Q} \leq 10,0001≤Q≤10,000) The next Q\mathbf{Q}Q lines will start with an integer 1, 2, 3 or 4 means the kind of this operation.

1.Given three integers u{u}u, v{v}v, w{w}w, for the u{u}u, v{v}v and all nodes between the path from u{u}u to v{v}v inclusive, you should update their weight to w{w}w. (1≤u,v≤N1 \leq u, v \leq \mathbf{N}1≤u,v≤N, 0≤w≤1,000,000,0000 \leq w \leq 1,000,000,0000≤w≤1,000,000,000)
2.Given three integers u{u}u, v{v}v, w{w}w, for the u{u}u, v{v}v and all nodes between the path from u{u}u to v{v}v inclusive, you should

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值