Tri-color Spanning Tree
Time limit2sMemory limit1024 MB
Count spanning trees of a three-colored graph with at most g green and at most b blue edges, modulo 1e9+7, for n up to 40.
- Level
Hard8 of 10
- Topics
- Graph, Matrix, Combinatorics
- Solved
- No attempts yet
Problem
bobo has an undirected graph whose edges are colored red, green, or blue. He wants to count the spanning trees of that have at most green edges and at most blue edges. Report the count modulo .
Input
The first line contains four integers , , , and . and are the number of vertices and edges of (, , ).
The vertices are numbered .
Each of the next lines contains three integers , , and , meaning that there is an edge between vertices and (, , ). The value means the -th edge is red, green, or blue, respectively.
Output
Print a single integer, the number of spanning trees.