#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.

题目大意

题目描述

FJ 有 BB 头奶牛 (1B25000)(1\le B\le 25000),有 N(2×BN50000)N(2\times B\le N\le 50000) 个农场,编号 11NN,有 M(N1M100000)M(N-1\le M\le 100000) 条双向边,第 ii 条边连接农场 RiR_iSi(1RiN,1SiN)S_i(1\le R_i\le N, 1\le S_i\le N),该边的长度是 Li(1Li2000)L_i(1\le L_i\le 2000)。居住在农场 PiP_i 的奶牛 A (1PiN)(1\le P_i\le N),想送一份新年礼物给居住在农场 Qi(1QiN)Q_i(1\le Q_i\le N) 的奶牛 B,但是奶牛 A 必须先到 FJ(居住在编号 11 的农场)那里取礼物,然后再送给奶牛 B。你的任务是:奶牛 A 至少需要走多远的路程?

输入格式

  • 第一行三个整数 N,M,BN,M,B

  • 22M+1M+1 行,每行 33 个整数 Ri,Si,LiR_i,S_i,L_i

  • M+2M+2M+B+1M+B+1 行,进行 BB 次询问,每行 22 个整数 Pi,QiP_i ,Q_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