PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000032. Mật thất Mount Rushmore (Secret Chamber at Mount Rushmore)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Mật thất Mount Rushmore (Secret Chamber at Mount Rushmore)
Secret Chamber at Mount Rushmore
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given directed letter translation rules, determine for each pair of words whether the first can be transformed to the second, letter-by-letter, using zero or more translations.
Input
Integers ; directed letter rules , followed by pairs of words.
Output
For every word pair print yes or no.
Subtasks
- Subtask 1 (40 points): , ; , ; distinct rules on different letters; word lengths , lowercase
a–zonly. - Subtask 2 (60 points): , ; distinct rules on different letters; word lengths , lowercase
a–zonly.
Examples
Input
3 3
a c
b a
a b
aaa abc
abc aaa
acm bcm
Output
yes
no
yes
Explanation
The letter a can become b or c, but c cannot be translated back into a. This validates the first and third word pairs, but not the second.