#P14122. [SCCPC 2021] Direction Setting

    ID: 15890 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>四川2021网络流Special Judge费用流XCPC

[SCCPC 2021] Direction Setting

题目描述

Given an undirected graph with nn vertices and mm edges where the ii-th vertex has a limit aia_i, please assign a direction for each edge so that the graph becomes directed and the following value DD is minimized. $$D = \sum\limits_{i=1}^n \max(0, d_i - a_i)$$ where did_i is the in-degree (that is, the number of edges going into that vertex) of the ii-th vertex.

输入格式

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (2n3002 \le n \le 300, 1m3001 \le m \le 300) indicating the number of vertices and edges.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai1040 \le a_i \le 10^4) where aia_i indicates the limit of the ii-th vertex.

For the following mm lines, the ii-th line contains two integers uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n) indicating that there is an edge connecting vertex uiu_i and viv_i. Note that there might be self loops or multiple edges.

It's guaranteed that neither the sum of nn nor the sum of mm of all test cases will exceed 3×1033 \times 10^3.

输出格式

For each test case output two lines. The first line contains an integer indicating the smallest possible DD. The second line contains a string s1s2sms_1s_2\cdots s_m of length mm consisting only of 0s and 1s indicating a direction assignment plan of the edges to achieve the smallest possible DD. If si=‘0’s_i = \text{`0'} then the ii-th edge is going from uiu_i into viv_i; Otherwise it's going from viv_i into uiu_i. If there are multiple valid answers you can output any of them.

2
4 5
0 1 1 5
1 2
1 3
2 3
3 2
4 4
3 2
0 0 2
1 3
3 2
2
00001
0
01

提示

The first sample test case is shown as follows.

:::align{center} :::