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
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main() {
    int res = 0;
    int n, m, k;
    cin>>n>>m>>k;
    vector <int> num(n+1);
    vector <bool> ok(n+1,0);
    for(int i = 1; i <= n; i++)
	cin>>num[i];
    vector <pii> step(m);
    for(int i = 0; i < m; i++)
	cin>>step[i].first>>step[i].second;
    vector <int> pair[200000];
    for(int i = 0; i < k; i++) {
	int tmp1,tmp2;
	cin>>tmp1>>tmp2;
	pair[tmp1].push_back(tmp2);
	pair[tmp2].push_back(tmp1);
    }
    for(int i = 0; i < m; i++) {
	ok[step[i].first] = ok[step[i].second] = 1;
	for(int j = 0; j < pair[step[i].first].size(); j++) {
	    if(ok[pair[step[i].first][j]] == 1 && num[pair[step[i].first][j]] > 0) {
		int temp = min(num[pair[step[i].first][j]],num[step[i].first]);
		res += 2*temp;
		num[pair[step[i].first][j]] -= temp;
		num[step[i].first] -= temp;
	    }
	}
    }
    cout<<res<<endl;
    
}