1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<cstdio>
long long m,n,k,g, t[200001], p[200001], s1[200000], s2[200000], n1[500000], n2[500000],i,j,a,b,wyn;
 
 int min (int a,int b) 
 {
   if (a<b) return a; else return b;  }
 
 int main()
  {
           scanf ("%lld%lld%lld", &n, &m, &k);
          
           for (i=1; i<=n; i++)
         {  scanf ("%lld", &t[i]);
           p[i]=i;}
      
          for (i=1; i<=m; i++)
          scanf ("%lld%lld", &s1[i], &s2[i]); 

           for (i=1; i<=k; i++)
           {
               scanf ("%lld%lld", &a, &b);
                 for (j=1; j<=m; j++)
                   {
                           p[s1[j]]=p[s2[j]];
                            if (p[a]==p[b])
                             {wyn=wyn+2*min(t[a], t[b]);
                             if (t[a]>t[b]) t[a]=t[a]-t[b]; else t[b]=t[b]-t[a];
                             break; }
                             }
                             }
                             printf ("%lld", wyn);
                             return 0;
   }