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
#include <algorithm>
#include <cstdio>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORD(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define REPD(i,n) FORD(i,0,n)
typedef long long LL;

int g[200000], a[200000], b[200000], c[500000], d[500000], fu[200000];
LL res;

int find(int i) {
	if (fu[i] == i) return i;
	return fu[i] = find(fu[i]);
}

void unify(int i, int j) {
	fu[find(i)] = find(j);
}

int main() {
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	REP(i,n) scanf("%d", &g[i]);
	REP(i,m) {
		scanf("%d%d", &a[i], &b[i]);
		--a[i];
		--b[i];
	}
	REP(i,k) {
		scanf("%d%d", &c[i], &d[i]);
		--c[i];
		--d[i];
	}
	REP(i,n) fu[i] = i;
	REP(i,m) {
		REP(j,k)if (find(c[j]) == a[i] && find(d[j]) == b[i] || find(d[j]) == a[i] && find(c[j]) == b[i]) {
			int r = min(g[c[j]], g[d[j]]);
			g[c[j]] -= r;
			g[d[j]] -= r;
			res += r << 1;
		}
		unify(a[i], b[i]);
	}
	printf("%lld\n", res);
}