This page is still under construction.

Parts of this page are still being built. What you see may change.

Commute

Time limit1sMemory limit1024 MB

Summary
A connected undirected graph has K alternative weight vectors; Yun may switch weight vectors at most K times at vertices and wants the cheapest trip from A to B.
Level

Medium7 of 10

Topics
Graph, Shortest path, Dynamic programming, Heap
Solved
No attempts yet

Problem

Yun lives in Uni Village. Uni Village has NN buildings numbered 11 through NN. Yun lives in building AA and commutes every day to the company in building BB.

Uni Village has the following structure. There are MM bidirectional roads RiR_i connecting the NN buildings, and by using the roads in a suitable order one can travel between any two buildings. Road RiR_i connects two distinct buildings UiU_i and ViV_i, and traversing RiR_i takes TiT_i time. There is at most one road directly connecting a given pair of buildings.

One day, Yun learned that by casting magic he can change the traffic conditions and thus change the time needed to traverse each road. Yun can cast magic at most KK times, and after casting magic kk times, the time needed to traverse road RiR_i becomes Ti,kT_{i, k} for every ii. Yun can cast magic only while he is in a building, and he cannot cast magic while traversing a road.

Yun wants to use magic appropriately to reach the company in the shortest time. Help Yun find the shortest time needed to reach the company.

Input

The first line of the input contains NN, MM, AA, and BB.

The next MM lines contain Ui,Vi,TiU_i, V_i, T_i separated by spaces. (1≤i≤M)(1 \le i \le M)

The next line contains KK.

Of the next KK lines, the kk-th line contains T1,k,T2,k,⋯ ,TM,kT_{1, k}, T_{2, k}, \cdots, T_{M, k} separated by spaces. (1≤k≤K)(1 \le k \le K)

Output

Print the shortest time needed for Yun to reach the company when he uses magic appropriately.

Constraints

  • 2≤N≤1,0002 \le N \le 1,000
  • N−1≤M≤2,000N-1 \le M \le 2,000
  • M≤N(N−1)/2M \le N(N-1)/2
  • 1≤A,B,Ui,Vi≤N,A≠B,Ui≠Vi1\le A, B, U_i, V_i\le N, A\ne B, U_i \ne V_i
  • 0≤K≤1000 \le K \le 100
  • 0≤Ti,Ti,k<1090 \le T_i, T_{i,k} < 10^9

Examples3

  1. Example 1

    Input
    2 1 2 1
    2 1 5
    0
    
    Expected output
    5
    
  2. Example 2

    Input
    3 2 1 3
    3 1 5
    3 2 5
    0
    
    Expected output
    5
    
  3. Example 3

    Input
    3 2 2 3
    3 1 1
    1 2 5
    2
    1 4
    5 4
    
    Expected output
    5