A7953 | String Problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary character $A_{i}$ in one of the strings into arbitrary character $B_{i}$ , but he has to pay for every move a particular sum of money, equal to $W_{i}$ . He is allowed to make as many moves as he needs. Since Valera is a very economical boy and never wastes his money, he asked you, an experienced programmer, to help him answer the question: what minimum amount of money should Valera have to get identical strings.
输入格式
The first input line contains two initial non-empty strings $s$ and $t$ , consisting of lower case Latin letters. The length of each string doesn't exceed $10^{5}$ . The following line contains integer $n$ ( $0\le n\le 500$ ) — amount of possible changings. Then follow $n$ lines, each containing characters $A_{i}$ and $B_{i}$ (lower case Latin letters) and integer $W_{i}$ ( $0\le W_{i}\le100$ ), saying that it's allowed to change character $A_{i}$ into character $B_{i}$ in any of the strings and spend sum of money $W_{i}$ .
输出格式
If the answer exists, output the answer to the problem, and the resulting string. Otherwise output -1 in the only line. If the answer is not unique, output any.
输入输出样例
输入 #1
uayd uxxd 3 a x 8 x y 13 d c 3
输出 #1
21 uxyd
输入 #2
a b 3 a b 2 a b 3 b a 5
输出 #2
2 b
输入 #3
abc ab 6 a b 4 a b 7 b a 8 c b 11 c a 3 a c 0
输出 #3
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted