source
[srcbox.git] / 193.pas
blobca142752ce585837f640f838c53bb9ced777844f
1 var
2 a:array [0..1000,0..1000] of longint;
3 n,m,i,min,j,k,x,y,t,ans:longint;
4 v:array [0..1000] of longint;
6 begin
7 readln(n,m);
8 for i:=1 to m do
9 begin
10 read(x,y);
11 readln(a[x,y]);
12 a[y,x]:=a[x,y];
13 end;
14 v[1]:=1;
15 for i:=1 to n-1 do
16 begin
17 min:=maxint; t:=1;
18 for j:=1 to n do
19 begin
20 if v[i]=1 then
21 begin
22 for k:=1 to n do
23 if (a[j,k]<min) and (a[j,k]<>0) then
24 begin
25 min:=a[j,k];
26 t:=j;
27 end;
28 end;
29 end;
30 if min<>maxint then
31 begin
32 ans:=ans+min;
33 v[t]:=1;
34 end;
35 end;
36 writeln(ans);
37 end.