atcoder#ARC093C. [ARC093E] Bichrome Spanning Tree
[ARC093E] Bichrome Spanning Tree
Score : points
Problem Statement
We have an undirected weighted graph with vertices and edges. The -th edge in the graph connects Vertex and Vertex , and has a weight of . Additionally, you are given an integer .
Find the number of ways to paint each edge in this graph either white or black such that the following condition is met, modulo :
- The graph has a spanning tree that contains both an edge painted white and an edge painted black. Furthermore, among such spanning trees, the one with the smallest weight has a weight of .
Here, the weight of a spanning tree is the sum of the weights of the edges contained in the spanning tree.
Constraints
- ()
- ()
- If , then and .
- ()
- The given graph is connected.
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 3
2
1 2 1
2 3 1
3 1 1
6
3 3
3
1 2 1
2 3 1
3 1 2
2
5 4
1
1 2 3
1 3 3
2 4 6
2 5 8
0
8 10
49
4 6 10
8 4 11
5 8 9
1 8 10
3 8 128773450
7 8 10
4 2 4
3 4 1
3 1 13
5 2 2
4