CF901D.Weighting a Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a connected undirected graph with nn vertices and mm edges. The vertices are enumerated from 11 to nn .

You are given nn integers c1,c2,...,cnc_{1},c_{2},...,c_{n} , each of them is between n-n and nn , inclusive. It is also guaranteed that the parity of cvc_{v} equals the parity of degree of vertex vv . The degree of a vertex is the number of edges connected to it.

You are to write a weight between 2n2-2·n^{2} and 2n22·n^{2} (inclusive) on each edge in such a way, that for each vertex vv the sum of weights on edges connected to this vertex is equal to cvc_{v} , or determine that this is impossible.

输入格式

The first line contains two integers nn and mm ( 2<=n<=1052<=n<=10^{5} , n1<=m<=105n-1<=m<=10^{5} ) — the number of vertices and the number of edges.

The next line contains nn integers c1,c2,...,cnc_{1},c_{2},...,c_{n} ( n<=ci<=n-n<=c_{i}<=n ), where cic_{i} is the required sum of weights of edges connected to vertex ii . It is guaranteed that the parity of cic_{i} equals the parity of degree of vertex ii .

The next mm lines describe edges of the graph. The ii -th of these lines contains two integers aia_{i} and bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n ; aibia_{i}≠b_{i} ), meaning that the ii -th edge connects vertices aia_{i} and bib_{i} .

It is guaranteed that the given graph is connected and does not contain loops and multiple edges.

输出格式

If there is no solution, print "NO".

Otherwise print "YES" and then mm lines, the ii -th of them is the weight of the ii -th edge wiw_{i} ( 2n2<=wi<=2n2-2·n^{2}<=w_{i}<=2·n^{2} ).

输入输出样例

  • 输入#1

    3 3
    2 2 2
    1 2
    2 3
    1 3
    

    输出#1

    YES
    1
    1
    1
    
  • 输入#2

    4 3
    -1 0 2 1
    1 2
    2 3
    3 4
    

    输出#2

    YES
    -1
    1
    1
    
  • 输入#3

    6 6
    3 5 5 5 1 5
    1 4
    3 2
    4 3
    4 5
    3 5
    5 6
    

    输出#3

    YES
    3
    5
    3
    -1
    -3
    5
    
  • 输入#4

    4 4
    4 4 2 4
    1 2
    2 3
    3 4
    4 1
    

    输出#4

    NO
首页