#P5642. 人造情感(emotion)
人造情感(emotion)
Background
“This task can never be completed. I will not repeat the same mistake again.”
“Having learned love and emotions, he is no longer a robot... From this point of view, 3000A is your son, Huo Xing.”
Farewell, 3000A! Detective Magic Horn
Problem Description
You are given a tree with nodes, and paths , where can be regarded as the weight assigned to the path . For a set of paths , its weight is defined as follows: find a subset of with the maximum possible sum of weights, such that no two paths in this subset share a common vertex. The sum of weights of all paths in this subset is .
Define as the smallest non-negative integer such that, for the path set formed by the given paths, we have .
Compute the following expression modulo :
Input Format
The first line contains two integers , representing the number of nodes in the tree and the number of given paths.
The next lines each contain two integers , describing an edge of the tree.
The next lines each contain three integers , meaning that a path with endpoints and weight is added into the set.
Output Format
Output one integer, the answer.
4 4
1 2
1 3
1 4
1 2 1
3 3 2
1 4 3
2 4 6
100
Hint
Sample 1 Explanation
Constraints
For of the testdata, it is guaranteed that , , and .
| Test Point | Special Property | |
|---|---|---|
| Tree structure | ||
| Given paths | ||
| Given paths | ||
| Tree structure | ||
| Tree structure | ||
| Tree structure | ||
Translated by ChatGPT 5