CF1749F.Distance to the Path

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree consisting of nn vertices. Initially, each vertex has a value 00.

You need to perform mm queries of two types:

  1. You are given a vertex index vv. Print the value of the vertex vv.
  2. You are given two vertex indices uu and vv and values kk and dd (d≤20d \le 20). You need to add kk to the value of each vertex such that the distance from that vertex to the path from uu to vv is less than or equal to dd.

The distance between two vertices xx and yy is equal to the number of edges on the path from xx to yy. For example, the distance from xx to xx itself is equal to 00.

The distance from the vertex vv to some path from xx to yy is equal to the minimum among distances from vv to any vertex on the path from xx to yy.

给你一棵包含 nn 个顶点的树。初始时,每个顶点的值均为 00。

你需要执行 mm 个查询,查询分为两类:

  1. 给定一个顶点编号 vv,输出顶点 vv 的当前值。
  2. 给定两个顶点编号 uu 和 vv,以及两个数值 kk 和 dd(其中 d≤20d \le 20)。你需要对所有满足“到 uu 到 vv 的路径的距离 ≤d\le d”的顶点,将其值增加 kk。

两个顶点 xx 和 yy 之间的距离定义为从 xx 到 yy 的路径上的边数。例如,顶点 xx 到其自身的距离为 00。

顶点 vv 到某条从 xx 到 yy 的路径的距离,定义为 vv 到该路径上任意顶点的最小距离。

输入格式

The first line contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of vertices in the tree.

Next n−1n - 1 lines contain the edges of the tree — one per line. Each line contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n; u≠vu \neq v) representing one edge of the tree. It's guaranteed that the given edges form a tree.

The next line contains a single integer mm (1≤m≤2⋅1051 \le m \le 2 \cdot 10^5) — the number of queries.

Next mm lines contain the queries — one per line. Each query has one of the following two types:

  • 11 vv (1≤v≤n1 \le v \le n) — the query of the first type;
  • 22 uu vv kk dd (1≤u,v≤n1 \le u, v \le n; 1≤k≤10001 \le k \le 1000; 0≤d≤200 \le d \le 20) — the query of the second type.

Additional constraint on the input: there is at least one query of the first type.

第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)——树中顶点的数量。

接下来的 n−1n - 1 行描述树的边,每行一条边。每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n;u≠vu \neq v),表示树中的一条边。保证所给的边构成一棵树。

接下来一行包含一个整数 mm(1≤m≤2⋅1051 \le m \le 2 \cdot 10^5)——查询的数量。

接下来的 mm 行描述查询,每行一个查询。每个查询为以下两种类型之一:

  • 11 vv(1≤v≤n1 \le v \le n)——第一类查询;
  • 22 uu vv kk dd(1≤u,v≤n1 \le u, v \le n;1≤k≤10001 \le k \le 1000;0≤d≤200 \le d \le 20)——第二类查询。

输入的附加约束:至少存在一个第一类查询。

输出格式

For each query of the first type, print the value of the corresponding vertex.

对于每个第一类查询,输出对应顶点的值。

输入输出样例

  • 输入#1

    6
    1 2
    1 3
    4 2
    5 2
    3 6
    14
    2 4 5 10 2
    1 3
    1 6
    2 1 1 10 20
    2 6 6 10 20
    1 3
    2 3 2 10 0
    2 5 2 10 1
    1 1
    1 2
    1 3
    1 4
    1 5
    1 6

    输出#1

    10
    0
    30
    50
    50
    40
    40
    40
    20

说明/提示

The tree from the first example:

Some query explanations:

  • "22 44 55 1010 22": affected vertices are 4,2,5,1,3{4, 2, 5, 1, 3};
  • "22 11 11 1010 2020" and "22 66 66 1010 2020": all vertices are affected, since distance to 11 (66) is less that 2020 for any vertex;
  • "22 33 22 1010 00": affected vertices are 3,1,2{3, 1, 2};
  • "22 55 22 1010 11": affected vertices are 5,2,4,1{5, 2, 4, 1}.

第一个示例中的树:

部分查询说明:

  • “22 44 55 1010 22”:受影响的顶点为 {4,2,5,1,3}\{4, 2, 5, 1, 3\};
  • “22 11 11 1010 2020” 和 “22 66 66 1010 2020”:所有顶点均受影响,因为任一顶点到顶点 11(即顶点 66)的距离均小于 2020;
  • “22 33 22 1010 00”:受影响的顶点为 {3,1,2}\{3, 1, 2\};
  • “22 55 22 1010 11”:受影响的顶点为 {5,2,4,1}\{5, 2, 4, 1\}。

输入解题思路,AI测评打分。不知道怎么写?

首页