2 1
1 1
2 1
 8 12
-6 2 -3 2 6 -7 1 -5
2 1
5 6
1 6
1 4
8 2
2 7
2 5
8 3
8 4
3 7
7 6
3 1
 10 13
3 4 -3 8 6 4 -5 1 3 -7
9 5
9 2
10 3
1 4
3 5
9 1
6 10
10 4
3 1
2 7
1 6
1 7
7 8
 43 52
-23 -18 -35 21 -12 38 -35 -11 28 -20 27 -5 9 -19 -39 -25 -32 32 -36 28 11 37 1 -25 -22 9 -15 21 25 -39 10 36 -30 -40 22 26 25 -27 -22 -38 -1 18 -13
33 40
31 23
30 26
21 17
6 2
41 19
32 39
32 23
13 14
25 35
31 30
19 32
25 22
34 36
7 40
23 6
40 12
1 3
23 43
36 13
18 33
17 32
7 3
21 34
41 35
20 7
23 1
41 8
25 19
20 29
42 5
40 21
9 37
17 41
30 10
41 18
39 1
20 24
20 4
42 3
20 25
5 16
31 9
42 28
10 11
19 42
31 38
25 2
31 27
17 25
13 15
31 20
 2 1
1 1
1 2
 5 7
4 1 5 3 -1
2 4
5 4
5 2
1 5
1 2
4 1
1 3
 10 12
5 1 1 8 -8 10 -3 -2 1 7
5 3
8 2
10 9
4 6
5 6
4 5
5 10
4 7
8 4
3 1
3 6
6 10
 20 40
-9 -10 -9 15 -3 -5 -17 -10 -6 2 -13 19 10 -15 15 -14 17 0 7 -8
3 17
6 18
15 12
2 5
18 3
16 20
6 17
20 10
10 18
9 12
15 3
6 4
15 16
20 6
20 9
9 4
4 8
14 5
11 7
12 11
3 13
14 19
7 17
16 14
19 7
12 13
14 13
13 11
9 14
13 17
8 19
5 20
2 17
2 16
12 5
8 1
20 3
6 2
5 18
13 8

YES
                                                               1
 NO
 YES
                                                              -7
                                                              10
                                                             -16
                                                               3
                                                              13
                                                               0
                                                               4
                                                               5
                                                               0
                                                              -6
                                                               0
                                                               0
                                                               1
 NO
 YES
                                                               1
 YES
                                                               2
                                                               1
                                                              -1
                                                              -1
                                                               0
                                                               0
                                                               5
 YES
-4
1
1
17
-7
-3
6
-3
-3
5
0
0
 YES
                                                             -30
                                                             -21
                                                             -23
                                                             -10
                                                              21
                                                             -52
                                                               0
                                                               2
                                                               0
                                                              -9
                                                               0
                                                              16
                                                              38
                                                               0
                                                              42
                                                               0
                                                              -1
                                                               7
                                                             -64
                                                              51
                                                               0
                                                               7
                                                              47
                                                               0
                                                               0
                                                               0
                                                              10
                                                               0
                                                             -39
                                                               0
                                                               0
                                                               0
                                                               0
                                                               0
                                                               0
                                                              -9
                                                               0
                                                               0
                                                               0
                                                               0

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DWeightingATree solver = new DWeightingATree();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DWeightingATree {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            Node[] nodes = new Node[n];
            for (int i = 0; i < n; i++) {
                nodes[i] = new Node();
                nodes[i].id = i;
                nodes[i].w = in.readInt();
            }
            DSU dsu = new DSU(n);
            Edge[] edges = new Edge[m];
            for (int i = 0; i < m; i++) {
                edges[i] = new Edge();
                edges[i].a = nodes[in.readInt() - 1];
                edges[i].b = nodes[in.readInt() - 1];
                if (dsu.find(edges[i].a.id) != dsu.find(edges[i].b.id)) {
                    edges[i].tree = true;
                    dsu.merge(edges[i].a.id, edges[i].b.id);
                    edges[i].a.next.add(edges[i]);
                    edges[i].b.next.add(edges[i]);
                }
            }

            dfs(nodes[0], null, 0);
            long diff = 0;
            for (Node node : nodes) {
                if (node.sign) {
                    diff += node.w;
                } else {
                    diff -= node.w;
                }
            }

            if (diff % 2 != 0) {
                out.println("NO");
                return;
            }

            for (Edge e : edges) {
                if (e.tree) {
                    continue;
                }
                if (e.a.sign != e.b.sign) {
                    continue;
                }
                if (e.a.sign) {
                    e.val = -diff / 2;
                } else {
                    e.val = diff / 2;
                }
                diff = 0;
                break;
            }

            if (diff != 0) {
                out.println("NO");
                return;
            }

            out.println("YES");
            for (Edge e : edges) {
                out.println(e.val);
            }
        }

        public long dfs(Node root, Node p, int d) {
            root.sign = d % 2 == 0;
            long w = root.w;
            for (Edge e : root.next) {
                Node node = e.other(root);
                if (node == p) {
                    continue;
                }
                long need = dfs(node, root, d + 1);
                e.val = need;
                w -= need;
            }
            return w;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(String c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println(long c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class Node {
        int id;
        List<Edge> next = new ArrayList<>();
        long w;
        boolean sign;

    }

    static class Edge {
        Node a;
        Node b;
        long val;
        boolean tree;

        Node other(Node x) {
            return a == x ? b : a;
        }

    }

    static class DSU {
        int[] p;
        int[] rank;

        public DSU(int n) {
            p = new int[n];
            rank = new int[n];
            reset();
        }

        public void reset() {
            for (int i = 0; i < p.length; i++) {
                p[i] = i;
                rank[i] = 0;
            }
        }

        public int find(int a) {
            return p[a] == p[p[a]] ? p[a] : (p[a] = find(p[a]));
        }

        public void merge(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
            if (rank[a] > rank[b]) {
                p[b] = a;
            } else {
                p[a] = b;
            }
        }

    }
}

