CF883F.Lost in Transliteration

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.

For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.

The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.

There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?

Formally, we assume that two words denote the same name, if using the replacements "u" "oo" and "h" "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.

For example, the following pairs of words denote the same name:

  • "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" "kuuper" and "kuooper" "kuuper".
  • "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" "khoon" and "kkkhoon" "kkhoon" "khoon".

For a given list of words, find the minimal number of groups where the words in each group denote the same name.

当人们用拉丁字母拼写伯兰德(Berland)名字时,存在一些歧义。

例如,伯兰德音素 u 既可用拉丁字母 "u" 表示,也可用 "oo" 表示。因此,单词 "ulyana" 和 "oolyana" 表示同一个名字。

第二种歧义涉及伯兰德音素 h:它既可用 "h" 表示,也可用 "kh" 表示。例如,单词 "mihail" 和 "mikhail" 表示同一个名字。

Polycarp 的网站上共注册了 n 位用户,每位用户均提供了一个仅由拉丁字母组成的姓名。若考虑上述两种歧义,这些姓名中实际有多少个互不相同的名字?

形式化地,我们定义:若通过对两个单词反复、任意次地应用如下两种替换(可在任一单词中、以任意顺序、任意次数进行;且某次替换产生的字母可参与后续替换),能使两单词变得完全相等,则这两个单词表示同一个名字:

  • "u" "oo"
  • "h" "kh"

例如,下列各组单词均表示同一个名字:

  • "koouper" 和 "kuooper"。通过上述替换,二者均可变为 "kuuper":
    "koouper" "kuuper",
    "kuooper" "kuuper"。

  • "khun" 和 "kkkhoon"。通过上述替换,二者均可变为 "khoon":
    "khun" "khoon",
    "kkkhoon" "kkhoon" "khoon"。

给定一个单词列表,请计算其最少可划分为多少个组,使得每组内所有单词均表示同一个名字。

输入格式

The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list.

The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.

第一行包含一个整数 $ n (( 2 \leq n \leq 400 $)——表示单词列表中单词的个数。

接下来的 $ n $ 行每行包含一个单词。每个单词仅由小写拉丁字母组成,且每个单词的长度在 $ 1 $ 到 $ 20 $ 个字母之间(含端点)。

输出格式

Print the minimal number of groups where the words in each group denote the same name.

输出单词分组的最少组数,使得每组内的单词表示相同的名字。

输入输出样例

  • 输入#1

    10
    mihail
    oolyana
    kooooper
    hoon
    ulyana
    koouper
    mikhail
    khun
    kuooper
    kkkhoon

    输出#1

    4
  • 输入#2

    9
    hariton
    hkariton
    buoi
    kkkhariton
    boooi
    bui
    khariton
    boui
    boi

    输出#2

    5
  • 输入#3

    2
    alex
    alex

    输出#3

    1

说明/提示

There are four groups of words in the first example. Words in each group denote same name:

  1. "mihail", "mikhail"
  2. "oolyana", "ulyana"
  3. "kooooper", "koouper"
  4. "hoon", "khun", "kkkhoon"

There are five groups of words in the second example. Words in each group denote same name:

  1. "hariton", "kkkhariton", "khariton"
  2. "hkariton"
  3. "buoi", "boooi", "boui"
  4. "bui"
  5. "boi"

In the third example the words are equal, so they denote the same name.

第一个示例中有四组单词,每组中的单词表示同一个名字:

  1. “mihail”、“mikhail”
  2. “oolyana”、“ulyana”
  3. “kooooper”、“koouper”
  4. “hoon”、“khun”、“kkkhoon”

第二个示例中有五组单词,每组中的单词表示同一个名字:

  1. “hariton”、“kkkhariton”、“khariton”
  2. “hkariton”
  3. “buoi”、“boooi”、“boui”
  4. “bui”
  5. “boi”

在第三个示例中,这些单词完全相同,因此它们表示同一个名字。

输入解题思路,AI测评打分。不知道怎么写?

首页