#ABC235H. [ABC235Ex] Painting Weighted Graph

[ABC235Ex] Painting Weighted Graph

Score : 600600 points

Problem Statement

Given is an undirected graph with NN vertices and MM edges. The ii-th edge connects Vertices AiA_i and BiB_i and has a weight of CiC_i.

Initially, all vertices are painted black. You can do the following operation at most KK times.

  • Operation: choose any vertex vv and any integer xx. Paint red all vertices reachable from the vertex vv by traversing edges whose weights are at most xx, including vv itself.

How many sets can be the set of vertices painted red after the operations? Find the count modulo 998244353998244353.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 0M1050 \leq M \leq 10^5
  • 1K5001 \leq K \leq 500
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • 1Ci1091 \leq C_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM KK

A1A_1 B1B_1 C1C_1

\vdots

AMA_M BMB_M CMC_M

Output

Print the answer.

3 2 1
1 2 1
2 3 2
6

For example, an operation with (v,x)=(2,1)(v,x)=(2,1) paints Vertices 1,21,2 red, and an operation with (v,x)=(1,0)(v,x)=(1,0) paints Vertex 11.

After at most one operation, the set of vertices painted red can be one of the following six: {},{1},{2},{3},{1,2},{1,2,3}\{\},\{1\},\{2\},\{3\},\{1,2\},\{1,2,3\}.

5 0 2
16

The given graph may not be connected.

6 8 2
1 2 1
2 3 2
3 4 3
4 5 1
5 6 2
6 1 3
1 2 10
1 1 100
40

The given graph may have multi-edges and self-loops.