#P11292. 【MX-S6-T4】「KDOI-11」彩灯晚会
【MX-S6-T4】「KDOI-11」彩灯晚会
Background
Original link: https://oier.team/problems/S6D.
Problem Description
Little K’s house is quite large, so he is holding a colored lights party.
A colored lights party obviously needs colored lights. So Little K found colored lights.
Little K does not want the lights scattered on the ground, so he connected these lights with directed edges so that they are connected together. That is, if we treat the directed edges as undirected edges, then these lights form a connected graph. It is guaranteed that this graph is a directed acyclic graph (DAG).
Little K’s lights are very powerful: each one can independently emit any one of colors. As a world-class Light Glowing Master (LGM for short), Little K decided to try all configurations (there are in total).
Little K does not like having too many colors, so he is given a positive integer , and defines the beauty of a configuration as the sum of squares of the number of length- chains of each color. Formally, let the number of length- chains of the -th color be , then the beauty of a configuration is .
Now Little K wants to know, over all configurations, the sum of their beauty values, modulo .
Two configurations are different if and only if there exists some light that emits different colors in the two configurations.
A length- chain is a -tuple such that for any , the -th directed edge goes from to . Two length- chains and are different if and only if there exists some with , or there exists some with .
A length- chain of color is a length- chain such that for every , the light with index emits color .
Input Format
The first line contains five non-negative integers , where is the test point index (all samples satisfy ), is the number of lights, is the number of colors, is the chain length, and the meaning of is described below.
The next lines: the -th line contains three positive integers , meaning there are directed edges . That is, the -th through the -th directed edges go from to .
In the statement, satisfies . It is guaranteed that: all pairs are distinct, the given graph is a DAG, and if directed edges are treated as undirected, the lights form a connected graph.
Output Format
Only one line: a non-negative integer, the sum of the beauty values over all configurations, modulo .
0 3 2 2 2
1 3 1
3 2 1
12
0 5 4 3 7
1 4 4
1 5 2
4 3 1
5 3 2
3 2 3
4 5 1
5 2 2
16096
Hint
[Sample Explanation #1]
There are different configurations of light colors, shown in the table below (assume the colors are black and white):
| Index | Color of light | Color of light | Color of light | Beauty |
|---|---|---|---|---|
| black | black | black | ||
| white | ||||
| white | black | |||
| white | ||||
| white | black | black | ||
| white | ||||
| white | black | |||
| white |
The sum of beauty values is .
[Sample #3]
See party/party3.in and party/party3.ans in the attachment.
This sample satisfies the constraints of test point .
[Sample #4]
See party/party4.in and party/party4.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #5]
See party/party5.in and party/party5.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #6]
See party/party6.in and party/party6.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #7]
See party/party7.in and party/party7.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #8]
See party/party8.in and party/party8.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #9]
See party/party9.in and party/party9.ans in the attachment.
This sample satisfies the constraints of test points .
[Constraints]
Let . For all testdata, it is guaranteed that: , , , , , all pairs are distinct, the given graph is a DAG, and if directed edges are treated as undirected, the lights form a connected graph.
| Test point index | Special properties | |||
|---|---|---|---|---|
| , | ||||
| None. | ||||
| and there is exactly one node with in-degree . | ||||
| None. | ||||
Translated by ChatGPT 5