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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<iostream>
#include<map>


using namespace std;

#define rep(i,n) for(int i=0; i<(int)n; i++)
#define st first
#define nd second
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpii;
typedef set<int> SI;
typedef long long LL;

#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif
int n,m,k,l, temp,a,b;
const int inf = 1000 * 1000 * 1000 ;
const int MAKSN = 200 * 1000 + 13; // UZUPElnic

map<int,int> zaw[MAKSN];
vector<pi> kroki;

vpii v;
LL ans;
set<pair<int,pi> > s;

const int randd = 8211;

void readIn()
{
	ans = 0LL;

	l = scanf("%d %d%d", &n, &m, &k);

	rep(i,n)
	{
		l = scanf("%d", &temp);
		zaw[i][i] = temp;
	}

	rep(i,m)
	{
		l = scanf("%d %d", &a, &b);
		a--;
		b--;
		kroki.pb(mp(a,b));
	}

	rep(i,k)
	{
		l = scanf("%d %d", &a, &b);
		a--;
		b--;

		if(a > b)
			swap(a,b);

		v.pb(mp(a,b));
		s.insert(mp(i,mp(a,b)));
	}
}

void genV()
{
	v.clear();

	for(auto it: s)
	{
		v.pb(mp(it.nd.st,it.nd.nd));
	}

}

void usun(vi doUsun)
{
	vector<pair<int,pi> > toDel;

	int nr;

	rep(i,doUsun.size())
	{
		nr = doUsun[i];

		for(auto it: s)
		{
			if(it.nd.st == nr || it.nd.nd == nr)
				toDel.pb(it);
		}
	}

	rep(i,toDel.size())
	{
		s.erase(toDel[i]);
	}

	k -= toDel.size();
	toDel.clear();

	if(k < randd)
		genV();
}

void przereaguj2(int nr)
{
	vi doUsun;
// 	rep(i,v.size())
	for(auto it: s)
	{

		if(zaw[nr].find(it.nd.st) != zaw[nr].end() && zaw[nr].find(it.nd.nd) != zaw[nr].end() &&
			zaw[nr][it.nd.st] > 0 && zaw[nr][it.nd.nd] > 0)
		{
			a = zaw[nr][it.nd.st];
			b = zaw[nr][it.nd.nd];
// 			printf("a(%d) b(%d)\n",a,b);
			l = min(a,b);

			if(a == l)
			{
				doUsun.pb(it.nd.st);
				zaw[nr].erase(it.nd.st);
			}
			else zaw[nr][a] -= l;


			if(b == l)
			{
				doUsun.pb(it.nd.nd);
				zaw[nr].erase(it.nd.nd);
			}
			else zaw[nr][b] -= l;

			ans += 2*l;
		}
	}


	usun(doUsun);

}

void przereaguj(int nr)
{
	rep(i,v.size())
	{
		if(zaw[nr].find(v[i].st) != zaw[nr].end() && zaw[nr].find(v[i].nd) != zaw[nr].end() &&
			zaw[nr][v[i].st] > 0 && zaw[nr][v[i].nd] > 0)
		{
			a = zaw[nr][v[i].st];
			b = zaw[nr][v[i].nd];

			l = min(a,b);

			if(a == l)
			{
				zaw[nr].erase(v[i].st);
			}
			else zaw[nr][a] -= l;


			if(b == l)
			{
				zaw[nr].erase(v[i].nd);
			}
			else zaw[nr][b] -= l;

			ans += 2*l;
		}
	}
}

void scal(int a, int b)
{

	if(zaw[a].size() > zaw[b].size())
		swap(zaw[a], zaw[b]);

	for(auto it: zaw[a])
	{
			zaw[b][it.first] = it.second;
	}

	if(k <= randd)
		przereaguj(b);
	else
		przereaguj2(b);

	zaw[a].clear();
}

void solve()
{
	rep(i, kroki.size())
	{
		scal(kroki[i].st, kroki[i].nd);
	}

	printf("%lld\n",ans);
}

int main()
{
	readIn();
	solve();
	return 0;
}