水 、 {$A+,B-,D-,E-,F-,G+,I-,L-,N+,O-,P+,Q-,R-,S-,T-,V-,X+,Y-} {$M 65520,0,655360} {$inline on} program kset; label 1; const maxlongint=10000000; type re=record data,link:longint; end; var i,j,k,n,m,x,y,sum,p,q,o,t,min,sp,sq:longint; a1:array[1..10000]of re; link,head,list,a,b,pre:array[1..10000]of longint; e,next:array[1..300000]of longint; c:array[1..10000]of boolean; ans:int64; procedure quicksort(l,r:longint);inline; var i,j,x,y,x1,x2:longint; begin i:=l; j:=r; x:=a1[(l+r)>>1].data; y:=a1[(l+r)>>1].link; while i<j do begin while a1[j].data>x do dec(j); while a1[i].data<x do inc(i); if i<=j then begin x1:=a1[j].data;x2:=a1[j].link;a1[j]:=a1[i];a1[i].data:=x1;a1[i].link:=x2;inc(i);dec(j);end; end; if l<j then quicksort(l,j); if r>i then quicksort(i,r); end; procedure find(x1:longint);inline; var i,j,p,q,l,r,x,y:longint; begin l:=0; r:=1; list[1]:=x1; repeat inc(l); x:=list[l]; p:=head[x]; while p<>0 do begin if not c[e[p]] then begin c[e[p]]:=true; y:=e[p]; pre[y]:=x; if b[y]=0 then if a1[y].data+a1[x1].data<min then begin min:=a1[y].data+a1[x1].data;sp:=y;sq:=x1;end else else begin inc(r); list[r]:=b[y]; end; end; p:=next[p]; end; until l=r; end; begin assign(input,'kset.in'); reset(input); assign(output,'kset.out'); rewrite(output); read(k,n,m); for i:=1 to n do begin read(a1[i].data); a1[i].link:=i; end; quicksort(1,n); for i:=1 to n do link[a1[i].link]:=i; for i:=1 to m do begin read(x,y); y:=link[y]; j:=link[x]; e[i]:=y; if head[j]=0 then head[j]:=i else begin p:=head[j]; while p<>0 do begin if e[p]=y then goto 1; q:=p; p:=next[p]; end; next[q]:=i; end; 1: x:=1; end; for j:=1 to k do begin fillchar(c,sizeof(c),0); min:=maxlongint; for i:=1 to n do if a[i]=0 then find(i); inc(ans,min); if j=k then break; fillchar(c,sizeof(c),0); find(sq); x:=sp; while x<>0 do begin o:=a[pre[x]]; a[pre[x]]:=x; b[x]:=pre[x]; x:=o; end; end; writeln(ans); close(input); close(output); end.