CF1824E.LuoTianyi and Cartridge
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
LuoTianyi is watching the anime Made in Abyss. She finds that making a Cartridge is interesting. To describe the process of making a Cartridge more clearly, she abstracts the original problem and gives you the following problem.
You are given a tree T consisting of n vertices. Each vertex has values ai and bi and each edge has values cj and dj.
Now you are aim to build a tree T′ as follows:
- First, select p vertices from T (p is a number chosen by yourself) as the vertex set S′ of T′.
- Next, select p−1 edges from T one by one (you cannot select one edge more than once).
- May you have chosen the j-th edge connects vertices xj and yj with values (cj,dj), then you can choose two vertices u and v in S′ that satisfy the edge (xj,yj) is contained in the simple path from u to v in T, and link u and v in T′ by the edge with values (cj,dj) (u and v shouldn't be contained in one connected component before in T′).
A tree with three vertices, min(A,C)=1,B+D=7, the cost is 7.
Selected vertices 2 and 3 as S′, used the edge (1,2) with cj=2 and dj=1 to link this vertices, now min(A,C)=2,B+D=4, the cost is 8.
Let A be the minimum of values ai in T′ and C be the minimum of values ci in T′. Let B be the sum of bi in T′ and D be the sum of values di in T′. Let min(A,C)⋅(B+D) be the cost of T′. You need to find the maximum possible cost of T′.
洛天依正在观看动画《来自深渊》。她发现制作“卡带”十分有趣。为了更清晰地描述制作卡带的过程,她对原问题进行了抽象,并向你提出了如下问题。
给定一棵包含 n 个顶点的树 T。每个顶点 i 具有值 ai 和 bi;每条边 j 具有值 cj 和 dj。
现在你需要构造一棵新树 T′,具体步骤如下:
- 首先,从 T 中任选 p 个顶点(p 由你自己决定)作为 T′ 的顶点集 S′;
- 接着,从 T 中逐条选出 p−1 条边(每条边至多被选一次);
- 假设你第 j 次选择的边连接顶点 xj 与 yj,其对应值为 (cj,dj),则你可在 S′ 中任选两个顶点 u 和 v,满足:在 T 中,边 (xj,yj) 位于 u 到 v 的唯一简单路径上;然后在 T′ 中用一条权值为 (cj,dj) 的边连接 u 与 v(注意:在加入该边前,u 与 v 在 T′ 中不能属于同一连通分量)。
一棵含三个顶点的树,min(A,C)=1, B+D=7,代价为 7。
选取顶点 2 和 3 作为 S′,使用边 (1,2)(其 cj=2、dj=1)连接这两个顶点,此时 min(A,C)=2, B+D=4,代价为 8。
令 A 表示 T′ 中所有顶点 ai 值的最小值,C 表示 T′ 中所有边 ci 值的最小值;
令 B 表示 T′ 中所有顶点 bi 值的总和,D 表示 T′ 中所有边 di 值的总和;
定义 T′ 的代价为 min(A,C)⋅(B+D)。
你需要求出 T′ 可能取得的最大代价。
输入格式
The first line contains one integer n (3≤n≤2⋅105) — the number of vertices in the tree T.
The second line contains n integers a1,a2,…,an (1≤ai≤2⋅105), where the i-th integer represents the ai value of the i-th vertex.
The third line contains n integers b1,b2,…,bn (1≤bi≤2⋅105), where the i-th integer represents the bi value of the i-th vertex.
Then n−1 lines follow, the j-th of them contains four integers xj,yj,cj,dj (1≤xj,yj≤n,1≤cj,dj≤2⋅105) representing the edge (xj,yj) and its values cj and dj respectively. It's guaranteed that edges form a tree.
第一行包含一个整数 n(3≤n≤2⋅105)——树 T 的顶点数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤2⋅105),其中第 i 个整数表示第 i 个顶点的 ai 值。
第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤2⋅105),其中第 i 个整数表示第 i 个顶点的 bi 值。
接下来是 n−1 行,第 j 行包含四个整数 xj,yj,cj,dj(1≤xj,yj≤n,1≤cj,dj≤2⋅105),表示边 (xj,yj) 及其对应的值 cj 和 dj。保证这些边构成一棵树。
输出格式
Print a single integer — the maximum possible cost of T′.
输出一个整数——T′ 的最大可能代价。
输入输出样例
输入#1
3 1 2 2 1 1 2 1 2 2 1 1 3 1 2
输出#1
8
输入#2
5 2 4 2 1 1 2 4 4 4 4 2 5 3 3 3 5 2 4 4 2 5 5 5 1 1 5
输出#2
35
输入#3
6 5 7 10 7 9 4 6 9 7 9 8 5 2 1 5 1 3 2 2 4 4 3 6 3 5 1 7 4 6 5 6 8
输出#3
216
输入#4
5 1000 1000 1 1000 1000 1000 1000 1 1000 1000 1 2 1 1 2 3 1000 1000 3 4 1000 1000 3 5 1000 1000
输出#4
7000000
说明/提示
The tree from the first example is shown in the statement.
The tree from the second example is shown below:

A=1,B=18,C=1,D=17, so the cost is min(1,1)⋅(18+17)=35.
第一个示例中的树如题面所示。
第二个示例中的树如下所示:

A=1,B=18,C=1,D=17,因此代价为 min(1,1)⋅(18+17)=35。
输入解题思路,AI测评打分。不知道怎么写?