CF1857G.Counting Graphs
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given a tree consisting of n vertices. A tree is a connected undirected graph without cycles. Each edge of the tree has its weight, wi .
Your task is to count the number of different graphs that satisfy all four conditions:
- The graph does not have self-loops and multiple edges.
- The weights on the edges of the graph are integers and do not exceed S .
- The graph has exactly one minimum spanning tree.
- The minimum spanning tree of the graph is the given tree.
Two graphs are considered different if their sets of edges are different, taking into account the weights of the edges.
The answer can be large, output it modulo 998244353 .
输入格式
The first line contains an integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains two integers n and S ( 2≤n≤2⋅105,1≤S≤109 ) — the number of vertices and the upper bound of the weights.
Then follow n−1 lines describing the tree, the i -th line contains three integers ui , vi , and wi ( 1≤ui,vi≤n,ui=vi,1≤wi≤S ) — an edge in the tree with weight wi .
It is guaranteed that the sum of n for all tests does not exceed 2⋅105 .
输出格式
For each test, output the number of different graphs that satisfy the conditions, modulo 998244353 .
输入输出样例
输入#1
4 2 5 1 2 4 4 5 1 2 2 2 3 4 3 4 3 5 6 1 2 3 1 3 2 3 4 6 3 5 1 10 200 1 2 3 2 3 33 3 4 200 1 5 132 5 6 1 5 7 29 7 8 187 7 9 20 7 10 4
输出#1
1 8 80 650867886
说明/提示
In the first sample, there is only one graph, which is the given tree.
In the second samle, the given tree looks like this:
All possible graphs for the second sample are shown below, the minimum spanning tree is highlighted in red: