A13247 | Red-Blue Graph
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a bipartite graph: the first part of this graph contains $n_1$ vertices, the second part contains $n_2$ vertices, and there are $m$ 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 $r$ coins) or paint it blue (it costs $b$ 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.
Initially, each edge is colorless. For each edge, you may either leave it uncolored (it is free), paint it red (it costs $r$ coins) or paint it blue (it costs $b$ 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 $n_1$ , $n_2$ , $m$ , $r$ and $b$ ( $1 \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 $n_1$ characters. Each character is either U, R or B. If the $i$ -th character is U, then the $i$ -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 $n_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 $m$ lines follow, the $i$ -th line contains two integers $u_i$ and $v_i$ ( $1 \le u_i \le n_1$ , $1 \le v_i \le n_2$ ) denoting an edge connecting the vertex $u_i$ from the first part and the vertex $v_i$ from the second part.
The graph may contain multiple edges.
The second line contains one string consisting of $n_1$ characters. Each character is either U, R or B. If the $i$ -th character is U, then the $i$ -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 $n_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 $m$ lines follow, the $i$ -th line contains two integers $u_i$ and $v_i$ ( $1 \le u_i \le n_1$ , $1 \le v_i \le n_2$ ) denoting an edge connecting the vertex $u_i$ from the first part and the vertex $v_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$ .
Otherwise, print an integer $c$ denoting the total cost of coloring, and a string consisting of $m$ characters. The $i$ -th character should be U if the $i$ -th edge should be left uncolored, R if the $i$ -th edge should be painted red, or B if the $i$ -th edge should be painted blue. If there are multiple colorings with minimum possible cost, print any of them.
Otherwise, print an integer $c$ denoting the total cost of coloring, and a string consisting of $m$ characters. The $i$ -th character should be U if the $i$ -th edge should be left uncolored, R if the $i$ -th edge should be painted red, or B if the $i$ -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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted