luogu#P8315. [COCI 2021/2022 #4] Šarenlist
[COCI 2021/2022 #4] Šarenlist
Background
On a warm summer night, Vito and his good friend Karlo lay on a forest clearing watching the stars. Suddenly, Vito shouted, “Karlo, look. All the trees around us are changing color.” “Wow, so colorful.” Karlo said in surprise. Indeed, the branches in the forest started changing color.
Problem Description
Vito and Karlo were fascinated by these colorful trees, and they also noticed a few things. Each tree they are watching can be seen as a tree graph, i.e., an undirected graph in which there is exactly one path between any two vertices. Each tree they are watching has the following property: the color on each edge is one of colors. If a path on the tree is colorful, it means that the path contains edges of at least two different colors.
By morning, all the magic of the trees had disappeared. Vito and Karlo still remember the endpoints of colorful paths. They want to know: how many different trees (edge colorings) can satisfy the conditions? Since the answer may be very large, output it modulo .
Input Format
The first line contains three integers , denoting the number of nodes in the tree, the number of colorful paths remembered by Vito and Karlo, and the total number of available colors for the branches.
The next lines: the -th line contains two integers , indicating that there is a tree edge between vertex and vertex .
The next lines: the -th line contains two integers , indicating that the path from vertex to vertex is a colorful path. It is guaranteed that and are not adjacent.
Output Format
Output a single line containing the number of possible trees that satisfy the conditions, modulo .
3 1 2
1 2
2 3
1 3
2
4 3 2
1 2
2 3
4 2
1 4
1 3
4 3
0
4 3 3
1 2
2 3
4 2
1 4
1 3
4 3
6
Hint
[Sample 1 Explanation]
In the first case, the edge between vertex and vertex is colored , and the edge between vertex and vertex is colored .
In the second case, the edge between vertex and vertex is colored , and the edge between vertex and vertex is colored .
[Constraints and Notes]
This problem uses bundled subtasks.
- Subtask 1 (10 pts): .
- Subtask 2 (15 pts): .
- Subtask 3 (10 pts): Each tree edge belongs to at most one of the colorful paths.
- Subtask 4 (10 pts): .
- Subtask 5 (65 pts): No additional constraints.
For of the testdata: , , , .
[Hints and Explanation]
The score distribution follows the original COCI problem, with a full score of .
Translated from T5 Šarenlist, COCI2021-2022 CONTEST #4.
Translated by ChatGPT 5