#include "testlib.h"
using namespace std;
#define int long long
int n;
vector <int> vec[200007];
long long H[200007];
long long S;
signed main(signed argc, char *argv[]) {
registerTestlibCmd(argc, argv);
n = inf.readLong();
for(int i = 1; i <= n; i++) {
H[i] = inf.readLong();
S += H[i];
}
S /= n;
for(int i = 1, x, y; i < n; i++) {
x = inf.readLong(); y = inf.readLong();
vec[x].push_back(y), vec[y].push_back(x);
}
int OrderAns = ans.readLong(), OrderUser = ouf.readLong();
if(OrderAns != OrderUser) {
quitf(_wa, "Your operation number is not equal to the answer. Read %lld, Expected %lld.", OrderUser, OrderAns);
}
for(int cas = 1; cas <= OrderUser; cas++) {
int x, y;
long long w;
x = ouf.readLong(1, n); y = ouf.readLong(1, n);
if(find(vec[x].begin(), vec[x].end(), y) == vec[x].end()) {
quitf(_wa, "There is not an edge connecting %lld and %lld", x, y);
}
w = ouf.readLong(0, H[x]);
H[x] -= w, H[y] += w;
}
for(int i = 1; i <= n; i++) {
if(H[i] != S) {
quitf(_wa, "H after operations is not equal.");
}
}
quitf(_ok, "Accepted");
return 0;
}