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
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<complex>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<stack>
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define fup FOR
#define fdo FORD
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define siz SZ
#define CLR(x) memset((x), 0, sizeof(x))
#define PB push_back
#define MP make_pair
#define X first
#define Y second 
#define FI X
#define SE Y
#define SQR(a) ((a)*(a))
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int>P;
typedef vector<int>VI;
const int INF=1E9+7;
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }

typedef set<int> Reactions;

struct Fiolka { LL capacity; Reactions reactions;};
const int MAX_FIOLKI = 200*1000;
const int MAX_REACTIONS = 500*1000;
const int MAX_EXPERIMENT = 200*1000;

int n,m,k;
Fiolka fiolki[MAX_FIOLKI+7];
P experiments[MAX_EXPERIMENT+7];
P reactions[MAX_REACTIONS+7];

LL react(P reaction) {
	Fiolka& c = fiolki[reaction.FI];
	Fiolka& d = fiolki[reaction.SE];
	LL s = min(c.capacity, d.capacity);
//	cerr<<"(c,d,c.cap,d.cap,s)=("<<reaction.FI<<','<<reaction.SE<<','<<c.capacity<<','<<d.capacity<<','<<s<<')'<<endl;
	c.capacity -= s; d.capacity -= s;
	return s;
}

LL conduct(P experiment) {
	LL sum = 0, from = experiment.FI, to = experiment.SE;
	Reactions& in = fiolki[from].reactions;
	Reactions& out = fiolki[to].reactions;
	if (SZ(in)>SZ(out))
		in.swap(out);

	FORE(i, in) {
		VAR(o, out.find(*i));
		if (o!=out.end()) {
			sum += react(reactions[*i]);
			out.erase(o);
		} else {
			out.insert(*i);
		}
	}
	in.clear();
	return sum;
}

int main(){
	ios_base::sync_with_stdio(false);
	cout << setprecision(15) << fixed;
	cin>>n>>m>>k;
	if (n==0 || m==0 || k==0) {cout<<'0'<<endl; return 0;}

	FOR(i,1,n) cin >> fiolki[i].capacity;
	FOR(i,1,m) {int a,b; cin >> a >> b; experiments[i] = MP(a,b);}
	FOR(i,1,k) {
		int c,d; cin >> c >> d;
		reactions[i] = MP(c,d);
		fiolki[c].reactions.insert(i);
		fiolki[d].reactions.insert(i);
	}
	LL sum = 0;
	FOR(i,1,m) sum += conduct(experiments[i]);
	cout << (2LL*sum) << endl;
	return 0;
}