#P1366F. Jog Around The Graph
Jog Around The Graph
Description
You are given a simple weighted connected undirected graph, consisting of vertices and edges.
A path in the graph of length is a sequence of vertices such that for each the edge is present in the graph. A path from some vertex also has vertex . Note that edges and vertices are allowed to be included in the path multiple times.
The weight of the path is the total weight of edges in it.
For each from to consider a path from vertex of length of the maximum weight. What is the sum of weights of these paths?
Answer can be quite large, so print it modulo .
The first line contains a three integers , , (; ; ) — the number of vertices in the graph, the number of edges in the graph and the number of lengths that should be included in the answer.
Each of the next lines contains a description of an edge: three integers , , (; ) — two vertices and are connected by an undirected edge with weight . The graph contains no loops and no multiple edges. It is guaranteed that the given edges form a connected graph.
Print a single integer — the sum of the weights of the paths from vertex of maximum weights of lengths modulo .
Input
The first line contains a three integers , , (; ; ) — the number of vertices in the graph, the number of edges in the graph and the number of lengths that should be included in the answer.
Each of the next lines contains a description of an edge: three integers , , (; ) — two vertices and are connected by an undirected edge with weight . The graph contains no loops and no multiple edges. It is guaranteed that the given edges form a connected graph.
Output
Print a single integer — the sum of the weights of the paths from vertex of maximum weights of lengths modulo .
Note
Here is the graph for the first example:

Some maximum weight paths are:
- length : edges — weight ;
- length : edges — weight ;
- length : edges — weight ;
- length : edges — weight ;
So the answer is the sum of terms:
In the second example the maximum weight paths have weights , , , and .