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
/// O(n*m*k)

#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define REP(x,n) for(int x=0;x<(n);++x)
#define FOR(a,b,e) for(int a=b;a<=(e);++a)
#define VAR(x,n) __typeof(n) x = (n)
#define FOREACH(x,n) for(VAR(x,(n).begin());x!=(n).end();++x)

int n,m,k;
typedef pair<int,int> PII;
const int MAX_N = 200001;
vector<int> reagenty[MAX_N];
int masy[MAX_N];
PII kroki[MAX_N];
int fiolki[2][MAX_N];

int main() {
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>k;
	REP(x,n)
		cin>>masy[x];
	REP(x,m) {
		cin>>kroki[x].first>>kroki[x].second;
		--kroki[x].first;
		--kroki[x].second;
	}
	int a,b;
	REP(x,k) {
		cin>>a>>b;
		reagenty[--a].push_back(--b);
		reagenty[b].push_back(a);
	}
	REP(x,n)
		fiolki[0][x] = x;
	long long suma=0;
	int reag;

	/// ///////////////////////////////////////// REP(x,m) {

	REP(x,10000) {
		REP(y,n)
			if (kroki[x].first==fiolki[x&1][y]) {
				fiolki[~x&1][y] = kroki[x].second;
				if (masy[y])
					FOREACH(it, reagenty[y]) {
						if (fiolki[x&1][*it] == kroki[x].second) {
							suma += 2*(reag = min(masy[y], masy[*it]));
							masy[y] -= reag;
							masy[*it] -= reag;
						}
					}
			} else
				fiolki[~x&1][y] = fiolki[x&1][y];

	}
	cout << suma << endl;
	return 0;
}