#FW0000080. Đồng nhất hai xâu (String Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đồng nhất hai xâu (String Problem)
String Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given two equally long lowercase strings and directed, positively weighted character-conversion rules, convert both strings into the same target string at minimum total cost. Among optimal results output the lexicographically smallest target.
Input
First string , second string , then and directed rules a b cost using lowercase characters.
Output
Print -1 if impossible; otherwise the minimum total cost and the target string on separate lines.
Subtasks
-
Subtask 1 (40 points): . Chỉ dùng chữ thường
a–z; ; mọi quy tắc có hướng. -
Subtask 2 (60 points): . Chỉ dùng chữ thường
a–z; ; mọi quy tắc có hướng.
Examples
Input
ab
bc
3
a b 3
b c 2
a c 10
Output
5
bc
Explanation
At position one, convert a into b for cost 3. At position two, convert b into c for cost 2. The common string bc costs 5.