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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<cstdio>
#include<vector>

#define MAXN 200003
#define MAXK 500003

using namespace std;

struct sub{
       int ind;
       int ilosc;       
};

sub act,pom;

int n,m,k;
//int g[MAXN];
int g,war;
int a[MAXN];
int b[MAXN];
int c[MAXK];
int d[MAXK];
int tab[MAXN];

long long res;
vector<sub> V[MAXN];

int main(){
    scanf("%d",&n);
    scanf("%d",&m);
    scanf("%d",&k);
    
    for(int i=0;i<n;i++){
            scanf("%d",&g);     
            pom.ind = i;
            pom.ilosc = g;
            V[i].push_back(pom);
    }
    for(int i=0;i<m;i++){
            scanf("%d %d",&a[i],&b[i]);   
            a[i]--;
            b[i]--;     
    }
    for(int i=0;i<k;i++){
            scanf("%d %d",&c[i],&d[i]);  
            c[i]--;
            d[i]--;      
    }
    
    for(int i=0;i<m;i++){
            //wrzuc substancje z V[a] i z V[b] do tablicy
            while(!V[a[i]].empty()){
                    act = V[a[i]].back();
                    V[a[i]].pop_back();
                    tab[act.ind] = act.ilosc;                        
            }
            while(!V[b[i]].empty()){
                    act = V[b[i]].back();
                    V[b[i]].pop_back();
                    tab[act.ind] = act.ilosc;                        
            }
            
            for(int j=0;j<k;j++){
                    war = min(tab[c[j]],tab[d[j]]);
                    tab[c[j]] -= war;
                    tab[d[j]] -= war;
                    res += war;        
            }
            for(int j=0;j<n;j++){
                    act.ind = j;
                    act.ilosc = tab[j];
                    if(act.ilosc > 0)V[b[i]].push_back(act);
                    tab[j] = 0;        
            }      
    }
    printf("%lld\n",(res*2LL));
    
    return 0;
}