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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Krzysztof Baranski
////////////////////////////////////////////////////////////////////
//                                                                //
//                           HEADERS                              //
//                                                                //
//////////////////////////////////////////////////////////////////// 
// includes
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <complex>
#include <iterator>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <cstdlib>
#include <ctime>
#include <list>
#include <unordered_map>
using namespace std;
// defines
#define FOR(x,b,e) for(int x=b; x<=(e); ++x)
#define FORD(x,b,e) for(int x=(b); x>=(e); --x)
#define FORK(x,b,e,k) for(int x=b; x<=(e); x+=k)
#define REP(x,n) for(int x=0; x<(n); ++x)
#define VAR(v,n) decltype(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define CLEAR(x) while(!(x).empty())(x).pop()
#define PB push_back
#define MP make_pair
#define ND second
#define ST first
#define POP(q) q.top(); q.pop()

#define __START__ int __z_;scanf("%d\n",&__z_);while(__z_--){
#define __STOP__ }return 0;
#define _INT(x) int x; scanf("%d",&x) 
// typedef
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef stack<int> SI;
typedef pair<int,int> PII;
typedef stack<PII> SPII;
typedef vector<char> VC;
typedef vector<VC> VVC;
// consts
const int INF = 1000000001;
const long long LINF = 1000000000000000001;
const double EPS = 10e-9;
////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------//
////////////////////////////////////////////////////////////////////


inline void READ(int* a)
{
    register char c=0;
    while((c=getchar_unlocked())<33);
    *a=0;
    do *a=*a*10+c-'0'; while((c=getchar_unlocked())>33);
}

struct pair_hash {
    inline std::size_t operator()(const std::pair<int,int> & v) const {
        return v.first*31+v.second;
    }
};


//==================================================================| MAIN
int main() {	
	int n,m,k,g,a,b,c,d;
	register LL osad=0;
	READ(&n);READ(&m);READ(&k);


	unordered_map<PII,int,pair_hash> reakcje_hash;
	vector<int> ilosci(n+1);
	vector<list<int> > fiolki(n+1);
	vector<PII> sekwencja(m+1);
	vector<PII> reakcje(k+1);
	
	FOR(i,1,n) {
		READ(&g);
		ilosci[i]=g;
		fiolki[i].PB(i);
	}
	
	FOR(i,1,m) {
		READ(&a);READ(&b);
		sekwencja[i]=MP(a,b);
	}
	
	FOR(i,1,k) {
		READ(&c);READ(&d);
		reakcje_hash[MP(c,d)]=i;
		reakcje_hash[MP(d,c)]=i;
		reakcje[i]=MP(c,d);
	}
	
	//FOREACH(r,reakcje_hash) cout<<"("<<r->ST.ST<<","<<r->ST.ND<<")\t"<<r->ND<<endl;
	
	FOR(i,1,m) {
		register int from = sekwencja[i].ST;
		register int to = sekwencja[i].ND;
		

		fiolki[to].splice(fiolki[to].end(),fiolki[from]);
		

		set<int> kolejnosc;
		FOREACH(skl1,fiolki[to]) {
			auto skl2=skl1;
			++skl2;
			while(skl2!=fiolki[to].end()) {
			
				auto got=reakcje_hash.find(MP(*skl1,*skl2));
				if(got!=reakcje_hash.end()) {
					
					kolejnosc.insert(got->ND);
					
				}
				++skl2;
			}
		}
		

		FOREACH(r,kolejnosc) {
			
			
			register int stracanie = min(ilosci[reakcje[*r].ST],ilosci[reakcje[*r].ND]);
			ilosci[reakcje[*r].ST]-=stracanie;
			ilosci[reakcje[*r].ND]-=stracanie;
			
			osad+=stracanie;
		}
		
		auto skl=fiolki[to].begin();
		while(skl!=fiolki[to].end()) {
		
			if(ilosci[*skl]==0) skl=fiolki[to].erase(skl);
			else ++skl;
			
		}
		

		
		
	}
	
	printf("%lld\n",osad<<1);
	
	
	return 0;
}