COCI '21 Contest 4 #5 Šarenlist

View as PDF

Submit solution


Points: 17 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem types

Warm summer night. Vito and his friend, Karlo, are lying in a forest clearing and watching the stars. Suddenly, Vito exclaims "Karlo, look! The trees around us are changing colors!" "Wooow so colorful" said Karlo, amazed. Indeed, the tree branches in the forest started to change colors.

Fascinated by the colorful trees, Vito and Karlo noticed a couple of facts about them. Each of the trees they are looking at can be represented as a tree graph, i.e. an undirected graph in which there exists a unique path between each pair of nodes. The trees they are looking at have the property that each edge of the tree is colored in one of k different colors. Some of the paths on the tree are colorful, meaning that such a path contains edges of at least two different colors.

Morning has arrived and the tree magic is now lost. In order to relive this experience, Vito and Karlo ask you to solve the following problem:

Given a tree and m pairs of nodes on the tree, determine the number of different colorings of the tree edges so that each of the m paths determined by the m pairs of nodes is colorful.

Since this number can be very large, output it modulo 10^9 + 7.

Input Specification

The first line contains three positive integers n, m, and k (3 \le n \le 60, 1 \le m \le 15, 2 \le k \le 10^9), the number of nodes in the tree, the number of path required to be colorful and the number of possible colors for the tree branches, respectively.

The i^\text{th} of the next n-1 lines contains a pair of positive integers a_i and b_i (1 \le a_i, b_i \le n), representing an edge of the tree.

The j^\text{th} of the next m lines contains a pair of positive integers c_j and d_j (1 \le c_j, d_j \le n), the labels of the endpoints of the paths which are required to be colorful. The nodes c_j and d_j are not neighboring.

Output Specification

In the only line, print the number of ways to color the tree edges so that each of the m given paths is colorful, modulo 10^9 + 7.

Constraints

SubtaskPointsConstraints
110m = 1
215m = 2
310Each tree edge belongs to at most one of the m given paths.
4101 \le n \le 15, k = 2
565No additional constraints.

Sample Input 1

3 1 2
1 2
2 3
1 3

Sample Output 1

2

Explanation for Sample Output 1

The tree consists of only two edges, both part of a colorful path between the nodes 1 and 3. So, the two edges must have a different color. One such coloring is obtained by coloring the edge 1-2 in color 1, and 2-3 in color 2, while the other is obtained by switching these color so that 1-2 has color 2, and 2-3 has color 1.

Sample Input 2

4 3 2
1 2
2 3
4 2
1 4
1 3
4 3

Sample Output 2

0

Sample Input 3

4 3 3
1 2
2 3
4 2
1 4
1 3
4 3

Sample Output 3

6

Comments

There are no comments at the moment.