#include
using namespace std;
struct edge { int t, c, v; edge *next, *rv; };
typedef long long dint; #ifdef WIN32 #define lld “%I64d” #else #define lld “%lld” #endif #define _l (long long int)
const int maxn = 509; const int maxm = 2009; const int maxe = 10009; const int inf = 0x3f3f3f3f;
dint ansc, ansv; int n, m, ea[maxm], eb[maxm], v[maxn], st, te; int d[maxm], fp[maxn]; edge *ep, *head[maxn], elst[maxe], *fe[maxn];
inline edge* newEdge(int u, int v, int c) { ep-> t = v; ep-> c = c; ep-> next = head[u]; return head[u] = ep ++; } inline void addEdge(int u, int v, int c) { edge *a(newEdge(u, v, c)); edge *b(newEdge(v, u, 0)); a-> rv = b; b-> rv = a; }
bool bfsBuild() { static int q[maxn]; int hd(0), tl(1); memset(d, 0, sizeof(d)); d[q[0] = st] = 1; while (hd ^ tl) { int p(q[hd ++]); for (edge* e = head[p]; e; e = e-> next) if (e-> c && !d[e-> t]) { d[e-> t] = d[p] + 1; q[tl ++] = e-> t; } } return d[te]; } int dfsFind(int p, int c) { if (p == te) return c; int s(0); edge *e; for (e = head[p]; e && c; e = e-> next) if (e-> c && d[e-> t] == d[p] + 1) { int x(dfsFind(e-> t, min(c, e-> c))); c -= x; s += x; e-> c -= x; e-> rv-> c += x; } if (!e) d[p] = 0; return s; }
#define mkword(x,y) (((x)«16)|(y)) #define hiword(x) ((x)»16) #define loword(x) ((x)&0xffff)
void flow(int lv) { st = n + 1; te = n + 2; ep = elst; memset(head, 0, sizeof(head)); for (int i = 1; i <= n; ++ i) if (v[i] >= 0) { if ((v[i] » lv) & 1) addEdge(st, i, inf); else addEdge(i, te, inf); } else addEdge(i, te, mkword(0, 1)); for (int i = 0; i < m; ++ i) if (v[ea[i]] < 0 && v[eb[i]] < 0) { addEdge(ea[i], eb[i], mkword(1, 0)); addEdge(eb[i], ea[i], mkword(1, 0)); } else if (v[ea[i]] < 0) { if ((v[eb[i]] » lv) & 1) addEdge(eb[i], ea[i], mkword(1, 0)); else addEdge(ea[i], eb[i], mkword(1, 0)); } int ans(0); while (bfsBuild()) ans += dfsFind(st, inf); ansc += (_l hiword(ans)) « lv; ansv += (_l loword(ans)) « lv; }
int main() { #ifndef ONLINE_JUDGE freopen(“in.txt”, “r”, stdin); #endif
ansc = ansv = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++ i) {
scanf("%d", v + i);
if (v[i] > 0)
ansv += v[i];
}
for (int i = 0; i < m; ++ i) {
scanf("%d%d", ea + i, eb + i);
if (v[ea[i]] >= 0 && v[eb[i]] >= 0)
ansc += v[ea[i]] ^ v[eb[i]];
if (v[eb[i]] < 0)
swap(ea[i], eb[i]);
}
for (int i = 0; i < 31; ++ i)
flow(i);
printf(lld "\n" lld "\n", ansc, ansv);
}