#P11292. 【MX-S6-T4】「KDOI-11」彩灯晚会

    ID: 12403 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DPO2优化动态规划优化拓扑排序组合数学容斥原理梦熊比赛

【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 nn colored lights.

Little K does not want the lights scattered on the ground, so he connected these lights with mm 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 kk colors. As a world-class Light Glowing Master (LGM for short), Little K decided to try all configurations (there are knk^n in total).

Little K does not like having too many colors, so he is given a positive integer ll, and defines the beauty of a configuration as the sum of squares of the number of length-ll chains of each color. Formally, let the number of length-ll chains of the ii-th color be cnticnt_i, then the beauty of a configuration is i=1kcnti2\sum_{i=1}^kcnt_i^2.

Now Little K wants to know, over all knk^n configurations, the sum of their beauty values, modulo 998244353998244353.

Two configurations are different if and only if there exists some light that emits different colors in the two configurations.

A length-ll chain is a (2l1)(2l-1)-tuple (v1,e1,v2,e2,,el1,vl)(v_1,e_1,v_2,e_2,\dots,e_{l-1},v_l) such that for any 1i<l1\leq i<l, the eie_i-th directed edge goes from viv_i to vi+1v_{i+1}. Two length-ll chains (v1,e1,v2,e2,,el1,vl)(v_1,e_1,v_2,e_2,\dots,e_{l-1},v_l) and (v1,e1,v2,e2,,el1,vl)(v'_1,e'_1,v'_2,e'_2,\dots,e'_{l-1},v'_l) are different if and only if there exists some 1i<l1\leq i<l with eieie_i\neq e'_i, or there exists some 1il1\leq i\leq l with viviv_i\neq v'_i.

A length-ll chain of color xx is a length-ll chain (v1,e1,v2,e2,,el1,vl)(v_1,e_1,v_2,e_2,\dots,e_{l-1},v_l) such that for every 1il1\leq i\leq l, the light with index viv_i emits color xx.

Input Format

The first line contains five non-negative integers id,n,k,l,Mid,n,k,l,M, where idid is the test point index (all samples satisfy id=0id=0), nn is the number of lights, kk is the number of colors, ll is the chain length, and the meaning of MM is described below.

The next MM lines: the ii-th line contains three positive integers ui,vi,ciu_i,v_i,c_i, meaning there are cic_i directed edges uiviu_i\to v_i. That is, the (j=1i1cj)+1\bigl(\sum_{j=1}^{i-1}c_j\bigr)+1-th through the (j=1icj)\bigl(\sum_{j=1}^ic_j\bigr)-th directed edges go from uiu_i to viv_i.

In the statement, mm satisfies m=i=1Mcim=\sum_{i=1}^Mc_i. It is guaranteed that: all pairs (u,v)(u,v) 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 knk^n configurations, modulo 998244353998244353.

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 23=82^3=8 different configurations of light colors, shown in the table below (assume the colors are black and white):

Index Color of light 11 Color of light 22 Color of light 33 Beauty
11 black black black 44
22 white 00
33 white black 11
44 white
55 white black black
66 white
77 white black 00
88 white 44

The sum of beauty values is 4+0+1+1+1+1+0+4=124+0+1+1+1+1+0+4=12.

[Sample #3]

See party/party3.in and party/party3.ans in the attachment.

This sample satisfies the constraints of test point 11.

[Sample #4]

See party/party4.in and party/party4.ans in the attachment.

This sample satisfies the constraints of test points 232\sim3.

[Sample #5]

See party/party5.in and party/party5.ans in the attachment.

This sample satisfies the constraints of test points 454\sim5.

[Sample #6]

See party/party6.in and party/party6.ans in the attachment.

This sample satisfies the constraints of test points 696\sim9.

[Sample #7]

See party/party7.in and party/party7.ans in the attachment.

This sample satisfies the constraints of test points 101210\sim12.

[Sample #8]

See party/party8.in and party/party8.ans in the attachment.

This sample satisfies the constraints of test points 131513\sim15.

[Sample #9]

See party/party9.in and party/party9.ans in the attachment.

This sample satisfies the constraints of test points 202120\sim21.

[Constraints]

Let P=998244353P=998244353. For all testdata, it is guaranteed that: 1n3001\leq n\leq300, 1Mn(n1)21\leq M\leq\frac{n(n-1)}{2}, 1k<P1\leq k<P, 1l201\leq l\leq 20, 1ci<P1\leq c_i<P, all pairs (ui,vi)(u_i,v_i) 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 nn\leq kk\leq ll\leq Special properties
11 66 m10m\leq10, ci=1c_i=1
232\sim3 300300 P1P-1 11 None.
454\sim5 22
696\sim9 33
101210\sim12 2020 M=n1M=n-1 and there is exactly one node with in-degree 00.
131513\sim15 3030 1010 None.
1616 150150 77
1717 1010
181918\sim19 1313
202120\sim21 300300 99
2222 1313
2323 1616
242524\sim25 2020

Translated by ChatGPT 5