CF1120D.Power Tree

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a rooted tree with nn vertices, the root of the tree is the vertex 11. Each vertex has some non-negative price. A leaf of the tree is a non-root vertex that has degree 11.

Arkady and Vasily play a strange game on the tree. The game consists of three stages. On the first stage Arkady buys some non-empty set of vertices of the tree. On the second stage Vasily puts some integers into all leaves of the tree. On the third stage Arkady can perform several (possibly none) operations of the following kind: choose some vertex vv he bought on the first stage and some integer xx, and then add xx to all integers in the leaves in the subtree of vv. The integer xx can be positive, negative of zero.

A leaf aa is in the subtree of a vertex bb if and only if the simple path between aa and the root goes through bb.

Arkady's task is to make all integers in the leaves equal to zero. What is the minimum total cost ss he has to pay on the first stage to guarantee his own win independently of the integers Vasily puts on the second stage? Also, we ask you to find all such vertices that there is an optimal (i.e. with cost ss) set of vertices containing this one such that Arkady can guarantee his own win buying this set on the first stage.

给你一棵包含 nn 个顶点的有根树,树的根为顶点 11。每个顶点具有某个非负价格。树的一个叶节点(leaf)是指非根节点且度数为 11 的顶点。

阿尔卡季(Arkady)和瓦西里(Vasily)在该树上进行一场奇特的游戏。游戏分为三个阶段:

  • 第一阶段,阿尔卡季购买树中某个非空的顶点集合;
  • 第二阶段,瓦西里向树的所有叶节点中填入某些整数;
  • 第三阶段,阿尔卡季可执行若干次(可能为零次)如下操作:选择一个他在第一阶段购买的顶点 vv 和某个整数 xx,然后将 xx 加到以 vv 为根的子树中所有叶节点所含的整数上。其中 xx 可为正数、负数或零。

叶节点 aa 属于顶点 bb 的子树,当且仅当 aa 到根节点的简单路径经过 bb。

阿尔卡季的目标是使所有叶节点中的整数都变为 00。问:为确保无论瓦西里在第二阶段填入何种整数,阿尔卡季都能获胜,他在第一阶段需支付的最小总费用 ss 是多少?此外,请找出所有满足如下条件的顶点:存在一个费用恰好为 ss 的最优顶点集合(即总费用为 ss 的集合),该集合包含此顶点,且阿尔卡季在第一阶段购买该集合即可保证获胜。

输入格式

The first line contains a single integer nn (2≤n≤200 0002 \le n \le 200\,000) — the number of vertices in the tree.

The second line contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (0≤ci≤1090 \le c_i \le 10^9), where cic_i is the price of the ii-th vertex.

Each of the next n−1n - 1 lines contains two integers aa and bb (1≤a,b≤n1 \le a, b \le n), denoting an edge of the tree.

第一行包含一个整数 nn(2≤n≤200 0002 \le n \le 200\,000)——树中顶点的数量。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(0≤ci≤1090 \le c_i \le 10^9),其中 cic_i 表示第 ii 个顶点的价格。

接下来的 n−1n - 1 行,每行包含两个整数 aa 和 bb(1≤a,b≤n1 \le a, b \le n),表示树中的一条边。

输出格式

In the first line print two integers: the minimum possible cost ss Arkady has to pay to guarantee his own win, and the number of vertices kk that belong to at least one optimal set.

In the second line print kk distinct integers in increasing order the indices of the vertices that belong to at least one optimal set.

第一行输出两个整数:Arkady 为确保自己获胜所需支付的最小可能费用 ss,以及属于至少一个最优集合的顶点个数 kk。

第二行按升序输出 kk 个互不相同的整数,即属于至少一个最优集合的顶点的编号。

输入输出样例

  • 输入#1

    5
    5 1 3 2 1
    1 2
    2 3
    2 4
    1 5

    输出#1

    4 3
    2 4 5
  • 输入#2

    3
    1 1 1
    1 2
    1 3

    输出#2

    2 3
    1 2 3

说明/提示

In the second example all sets of two vertices are optimal. So, each vertex is in at least one optimal set.

在第二个例子中,所有包含两个顶点的集合都是最优的。因此,每个顶点至少属于一个最优集合。

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

首页