#P2984. [USACO10FEB] Chocolate Giving S

[USACO10FEB] Chocolate Giving S

题目描述

Farmer John is distributing chocolates at the barn for Valentine's day, and BB (1B250001 \le B \le 25000) of his bulls have a special cow in mind to receive a chocolate gift.

Each of the bulls and cows is grazing alone in one of the farm's NN (2×BN500002\times B \le N \le 50000) pastures conveniently numbered 1N1\dots N and connected by MM (N1M105N-1 \le M \le 10^5) bidirectional cowpaths of various lengths. Some pastures might be directly connected by more than one cowpath. Cowpath ii connects pastures RiR_i and SiS_i (1RiN1 \le R_i \le N; 1SiN1 \le S_i \le N) and has length LiL_i (1Li20001 \le L_i \le 2000).

Bull ii resides in pasture PiP_i (1PiN1 \le P_i \le N) and wishes to give a chocolate to the cow in pasture QiQ_i (1QiN1 \le Q_i \le N).

Help the bulls find the shortest path from their current pasture to the barn (which is located at pasture 11) and then onward to the pasture where their special cow is grazing. The barn connects, one way or another (potentially via other cowpaths and pastures) to every pasture.

As an example, consider a farm with 66 pastures, 66 paths, and 33 bulls (in pastures 22, 33, and 55) who wish to bestow chocolates on their love-objects:


                      *1  <-- Bull wants chocolates for pasture 1 cow
             [4]--3--[5]  <-- [5] is the pasture ID
            /  |
           /   |
          4    2          <-- 2 is the cowpath length
         /     |               between [3] and [4]
      [1]--1--[3]*6
     /   \    /
    9     3  2
   /       \/
 [6]      [2]*4

* The Bull in pasture 22 can travel distance 33 (two different ways) to get to the barn then travel distance 2+12+1 to pastures [3][3] and [4][4] to gift his chocolate. That's 66 altogether.

* The Bull in pasture 55 can travel to pasture 44 (distance 33), then pastures 33 and 11 (total: 3+2+1=63 + 2 + 1 = 6) to bestow his chocolate offer.

* The Bull in pasture 33 can travel distance 11 to pasture 11 and then take his chocolate 99 more to pasture 66, a total distance of 1010.

输入格式

* Line 11: Three space separated integers: NN, MM, and BB;

* Lines 2M+12\dots M+1: Line i+1i+1 describes cowpath ii with three space-separated integers: RiR_i, SiS_i, and LiL_i;

* Lines M+2M+B+1M+2\dots M+B+1: Line M+i+1M+i+1 contains two space separated integers: PiP_i and QiQ_i.

输出格式

* Lines 1B1\dots B: Line ii should contain a single integer, the smallest distance that the bull in pasture PiP_i must travel to get chocolates from the barn and then award them to the cow of his dreams in pasture QiQ_i.

6 7 3 
1 2 3 
5 4 3 
3 1 1 
6 1 9 
3 4 2 
1 4 4 
3 2 2 
2 4 
5 1 
3 6 

6 
6 
10