CF1288F.Red-Blue Graph

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a bipartite graph: the first part of this graph contains n1n_1 vertices, the second part contains n2n_2 vertices, and there are mm edges. The graph can contain multiple edges.

Initially, each edge is colorless. For each edge, you may either leave it uncolored (it is free), paint it red (it costs rr coins) or paint it blue (it costs bb coins). No edge can be painted red and blue simultaneously.

There are three types of vertices in this graph — colorless, red and blue. Colored vertices impose additional constraints on edges' colours:

  • for each red vertex, the number of red edges indicent to it should be strictly greater than the number of blue edges incident to it;
  • for each blue vertex, the number of blue edges indicent to it should be strictly greater than the number of red edges incident to it.

Colorless vertices impose no additional constraints.

Your goal is to paint some (possibly none) edges so that all constraints are met, and among all ways to do so, you should choose the one with minimum total cost.

输入格式

The first line contains five integers n1n_1 , n2n_2 , mm , rr and bb ( 1n1,n2,m,r,b2001 \le n_1, n_2, m, r, b \le 200 ) — the number of vertices in the first part, the number of vertices in the second part, the number of edges, the amount of coins you have to pay to paint an edge red, and the amount of coins you have to pay to paint an edge blue, respectively.

The second line contains one string consisting of n1n_1 characters. Each character is either U, R or B. If the ii -th character is U, then the ii -th vertex of the first part is uncolored; R corresponds to a red vertex, and B corresponds to a blue vertex.

The third line contains one string consisting of n2n_2 characters. Each character is either U, R or B. This string represents the colors of vertices of the second part in the same way.

Then mm lines follow, the ii -th line contains two integers uiu_i and viv_i ( 1uin11 \le u_i \le n_1 , 1vin21 \le v_i \le n_2 ) denoting an edge connecting the vertex uiu_i from the first part and the vertex viv_i from the second part.

The graph may contain multiple edges.

输出格式

If there is no coloring that meets all the constraints, print one integer 1-1 .

Otherwise, print an integer cc denoting the total cost of coloring, and a string consisting of mm characters. The ii -th character should be U if the ii -th edge should be left uncolored, R if the ii -th edge should be painted red, or B if the ii -th edge should be painted blue. If there are multiple colorings with minimum possible cost, print any of them.

输入输出样例

  • 输入#1

    3 2 6 10 15
    RRB
    UB
    3 2
    2 2
    1 2
    1 1
    2 1
    1 1

    输出#1

    35
    BUURRU
  • 输入#2

    3 1 3 4 5
    RRR
    B
    2 1
    1 1
    3 1

    输出#2

    -1
  • 输入#3

    3 1 3 4 5
    URU
    B
    2 1
    1 1
    3 1

    输出#3

    14
    RBB
首页