AT_awtf2026algo_a.Min Cut of Graph of Min Weight
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a weighted tree T with N vertices numbered 1 to N. The i-th edge of T connects vertices Ai and Bi with weight Ci.
We now construct a complete undirected graph G with N vertices numbered 1 to N, based on T. For each edge of G, the capacity is defined as follows.
- The capacity of edge (i,j) of G is the minimum weight of an edge contained in the path connecting vertices i and j on T.
Let f(i,j) be the capacity of the minimum cut separating vertices i and j on G.
Find ∑1≤i<j≤Nf(i,j), modulo 998244353.
Solve S cases for each input.
存在一棵带权树 T,其包含 N 个编号为 1 至 N 的顶点。树 T 的第 i 条边连接顶点 Ai 和 Bi,权重为 Ci。
现在,我们基于 T 构造一个包含 N 个编号为 1 至 N 的顶点的无向完全图 G。对于 G 中的每条边,其容量定义如下:
- 图 G 中边 (i,j) 的容量等于树 T 上连接顶点 i 和 j 的路径中所含边的最小权重。
令 f(i,j) 表示图 G 中分离顶点 i 和 j 的最小割的容量。
求 ∑1≤i<j≤Nf(i,j) 对 998244353 取模的结果。
对每组输入,需解决 S 个测试用例。
输入格式
The input is given from Standard Input in the following format:
S
case1
case2
⋮
caseS
Each test case is given in the following format:
N
A1 B1 C1
A2 B2 C2
⋮
AN−1 BN−1 CN−1
输入从标准输入中按以下格式给出:
S
case1
case2
⋮
caseS
每个测试用例按以下格式给出:
N
A1 B1 C1
A2 B2 C2
⋮
AN−1 BN−1 CN−1
输出格式
For each test case, output the answer.
对于每个测试用例,输出答案。
输入输出样例
输入#1
4 3 1 2 1 2 3 10 4 1 2 1 2 3 10 3 4 2 13 11 4 337329830 13 1 72247 4 1 1768959 5 4 5399893 2 8 1832265 12 7 107755 10 4 743 5 12 95 4 3 389684075 2 6 1222 11 8 253280162722 9 4 21671 15 8 5 285187324995 14 10 755031423304 2 8 88860861719 12 7 596982637940 10 4 225447687713 7 15 210989590191 13 5 836365489027 6 15 859904883890 8 1 362117197524 12 8 422952343663 1 14 112179584332 15 11 487330735107 12 9 528451854379 3 7 343910842803
输出#1
15 32 13620068 909241492
说明/提示
Sample 1 Explanation:
In the first test case, the capacities of edges (1,2),(1,3),(2,3) of G are 1,1,10, respectively. The answer is f(1,2)+f(1,3)+f(2,3)=2+2+11=15.
Constraints
- 1≤S≤125000
- 2≤N≤250000
- 1≤Ai,Bi≤N
- 1≤Ci≤1012
- The input graph is a tree.
- The sum of N over the S cases is at most 250000.
- All input values are integers.
样例 1 解释:
在第一个测试用例中,图 G 中边 (1,2)、(1,3)、(2,3) 的容量分别为 1、1、10。答案为 f(1,2)+f(1,3)+f(2,3)=2+2+11=15。
约束条件
- 1≤S≤125000
- 2≤N≤250000
- 1≤Ai,Bi≤N
- 1≤Ci≤1012
- 输入图是一棵树。
- 所有 S 个测试用例的 N 值之和不超过 250000。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?