# [BZOJ2015][Usaco2010 Feb]Chocolate Giving

## [Usaco2010 Feb]Chocolate Giving

#### 题目描述

Farmer John有B头奶牛(1<=B<=25000)，有N(2*B<=N<=50000)个农场，编号1-N，有M(N-1<=M<=100000)条双向边，第i条边连接农场R_i和S_i(1<=R_i<=N;1<=S_i<=N)，该边的长度是L_i(1<=L_i<=2000)。居住在农场P_i的奶牛A(1<=P_i<=N)，它想送一份新年礼物给居住在农场Q_i(1<=Q_i<=N)的奶牛B，但是奶牛A必须先到FJ(居住在编号1的农场)那里取礼物，然后再送给奶牛B。你的任务是：奶牛A至少需要走多远的路程？

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

var
w:array[0..200005,1..3]of longint;
t:array[0..100005]of longint;
dist,p:array[0..50005]of longint;
i,j,k:longint;
n,m,s:longint;
a,b,c:longint;
procedure spfa;
var a,i:longint;
begin
a:=1;
for i:=1 to n do
dist[i]:=50000000;
begin
for i:=x to y-1 do
begin
tt:=w[t[i],3];
while tt<>0 do
begin
if dist[t[i]]+w[tt,2]<dist[w[tt,1]]
then
begin
dist[w[tt,1]]:=dist[t[i]]+w[tt,2];
if p[w[tt,1]]=0 then begin p[w[tt,1]]:=1; t[tail]:=w[tt,1]; inc(tail); end;
end;
tt:=w[tt,3];
end;
end;
end;
end;

begin
for i:=1 to m do
begin
w[w[0,1],1]:=b; w[w[0,1],2]:=c;
if w[a,3]=0
then w[a,3]:=w[0,1] else w[w[a,1],3]:=w[0,1];
w[a,1]:=w[0,1]; inc(w[0,1]);
w[w[0,1],1]:=a; w[w[0,1],2]:=c;
if w[b,3]=0
then w[b,3]:=w[0,1] else w[w[b,1],3]:=w[0,1];
w[b,1]:=w[0,1]; inc(w[0,1]);
end;
spfa;
for i:=1 to s do
begin
ans:=dist[a]+dist[b];
writeln(ans);
end;
end.

#### BZOJ2015 [Usaco2010 Feb]Chocolate Giving

2017-11-08 10:31:40

#### bzoj2015 [Usaco2010 Feb]Chocolate Giving

2014-08-06 21:52:06

#### bzoj2015 [Usaco2010 Feb]Chocolate Giving（最短路裸题）

2017-09-06 10:07:41

#### chocolate giving[usaco2010 Feb]

2017-03-25 08:57:08

#### 2015: [Usaco2010 Feb]Chocolate Giving

2016-11-15 14:16:14

#### [BZOJ1782] [Usaco2010 Feb]slowdown 慢慢游

2015-11-01 20:14:57

#### bzoj1782: [Usaco2010 Feb]slowdown 慢慢游

2015-09-29 18:48:50

#### BZOJ 2015: [Usaco2010 Feb]Chocolate Giving spfa

2017-05-27 11:06:31

#### bzoj 2015: [Usaco2010 Feb]Chocolate Giving

2017-07-22 16:32:56

#### [bzoj2015&&Usaco2010 Feb] Chocolate Giving

2016-07-05 11:18:21