308973: CF1606F. Tree Queries
Memory Limit:512 MB
Time Limit:6 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Tree Queries
题意翻译
给定一棵 $n$ 个节点的树,根节点为 $1$。 $q$ 次询问,每次询问给定两个整数 $v,k$,你可以通过任何顺序删除删除树中除根节点以及 $v$ 的任意节点。当一个节点 $u$ 被删除时,$u$ 的子节点将成为 $u$ 的父亲的子节点。你需要通过某种方式删除节点后使得 $c(v)-mk$ 的值尽量大。其中,$c(v)$ 表示 $v$ 的子节点数量,$m$ 表示删除节点的数量。 **注意,询问之间是互相独立的。** Translated by UperFicial.题目描述
You are given a tree consisting of $ n $ vertices. Recall that a tree is an undirected connected acyclic graph. The given tree is rooted at the vertex $ 1 $ . You have to process $ q $ queries. In each query, you are given a vertex of the tree $ v $ and an integer $ k $ . To process a query, you may delete any vertices from the tree in any order, except for the root and the vertex $ v $ . When a vertex is deleted, its children become the children of its parent. You have to process a query in such a way that maximizes the value of $ c(v) - m \cdot k $ (where $ c(v) $ is the resulting number of children of the vertex $ v $ , and $ m $ is the number of vertices you have deleted). Print the maximum possible value you can obtain. The queries are independent: the changes you make to the tree while processing a query don't affect the tree in other queries.输入输出格式
输入格式
The first line contains one integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of vertices in the tree. Then $ n-1 $ lines follow, the $ i $ -th of them contains two integers $ x_i $ and $ y_i $ ( $ 1 \le x_i, y_i \le n $ ; $ x_i \ne y_i $ ) — the endpoints of the $ i $ -th edge. These edges form a tree. The next line contains one integer $ q $ ( $ 1 \le q \le 2 \cdot 10^5 $ ) — the number of queries. Then $ q $ lines follow, the $ j $ -th of them contains two integers $ v_j $ and $ k_j $ ( $ 1 \le v_j \le n $ ; $ 0 \le k_j \le 2 \cdot 10^5 $ ) — the parameters of the $ j $ -th query.
输出格式
For each query, print one integer — the maximum value of $ c(v) - m \cdot k $ you can achieve.
输入输出样例
输入样例 #1
8
6 7
3 2
8 3
5 7
7 4
7 1
7 3
6
1 0
1 2
1 3
7 1
5 0
7 200000
输出样例 #1
5
2
1
4
0
4