From Constanța 2 Timișoara

Time limit: 0.6s
Memory limit: 128MB
Input:
Output:

Adi of Adi and Sorin would like to visit their country this summer. They live in a country that can be represented as a graph with NN nodes and MM edges, where each city is a node and each bidirectional road between two cities is a weighted edge in the same graph (where the weight of the edge represents the length of the road in kilometers).

Since they really like the cities Constanța and Timișoara, they decided to visit both of these cities in their vacantion. More formaly, we will note the city of Constanța as node XX and the city of Timișoara as node YY. Now, if they want to start their journey in city uu and end it in city vv, then their path will have the following properties:

  • the length of the path is as small as possible (where the length is equal to the sum of weights of the edges in the path);
  • the path visits both XX and YY.

Task

Let d(u,v)d(u, v) be the length of the path that Adi of Adi and Sorin will visit if they start their journey in node uu and end it in node vv. Note that a node or an edge can occur multiple times in the path. Your task is to calculate 1u<vNd(u,v)\sum_{ 1 \leq u < v \leq N} d (u, v). Since this number can be very large, calculate it modulo 109+910^{9} + 9.

Input data

The first line of the input contains the numbers NN, XX, YY and MM. The next MM lines will each contain three numbers uu, vv and cc, representing a weighted edge between uu and vv of weight cc.

Output data

Output a single number, the sum of d(u,v)d(u, v) for all ordered pairs of nodes modulo 109+910^{9} + 9.

Constraints and clarifications

  • 1N,M250 0001 \leq N , M \leq 250 \ 000
  • 1X,YN1 \leq X ,Y \leq N
  • 1u,vN1 \leq u, v \leq N
  • 1c1091 \leq c \leq 10^{9}
  • There will be no self-loops or multiple edges in the input.
# Points Constraints
1 12 1N1001 \leq N \leq 100, 1M2001 \leq M \leq 200
2 29 1N2 0001 \leq N \leq 2 \ 000, 1M4 0001 \leq M \leq 4 \ 000
3 59 No additional constraints.

Example

stdin

3 2 1 3
1 2 1
3 1 1
3 2 3

stdout

6

Explanation

d(1,2)+d(1,3)+d(2,3)=1+3+2=6d(1, 2) + d(1, 3) + d(2, 3) = 1 + 3 + 2 = 6

Log in or sign up to be able to send submissions!