CF1656F.Parametric MST
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n integers a1,a2,…,an. For any real number t, consider the complete weighted graph on n vertices Kn(t) with weight of the edge between vertices i and j equal to wij(t)=ai⋅aj+t⋅(ai+aj).
Let f(t) be the cost of the minimum spanning tree of Kn(t). Determine whether f(t) is bounded above and, if so, output the maximum value it attains.
给你 n 个整数 a1,a2,…,an。对于任意实数 t,考虑一个具有 n 个顶点的完全加权图 Kn(t),其中顶点 i 与顶点 j 之间的边的权重为 wij(t)=ai⋅aj+t⋅(ai+aj)。
令 f(t) 表示图 Kn(t) 的最小生成树 的总权重。判断 f(t) 是否有上界;若存在上界,则输出其能达到的最大值。
输入格式
The input consists of multiple test cases. The first line contains a single integer T (1≤T≤104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer n (2≤n≤2⋅105) — the number of vertices of the graph.
The second line of each test case contains n integers a1,a2,…,an (−106≤ai≤106).
The sum of n for all test cases is at most 2⋅105.
输入包含多个测试用例。第一行包含一个整数 T(1≤T≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105),表示图中顶点的数量。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−106≤ai≤106)。
所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, print a single line with the maximum value of f(t) (it can be shown that it is an integer), or INF if f(t) is not bounded above.
对于每个测试用例,输出一行,包含 f(t) 的最大值(可以证明该值为整数);若 f(t) 无上界,则输出 INF。
输入输出样例
输入#1
5 2 1 0 2 -1 1 3 1 -1 -2 3 3 -1 -2 4 1 2 3 -4
输出#1
INF -1 INF -6 -18
输入解题思路,AI测评打分。不知道怎么写?