CF1263D.Secret Passwords

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of paper with a list of nn passwords — strings, consists of small Latin letters.

Hacker went home and started preparing to hack AtForces. He found that the system contains only passwords from the stolen list and that the system determines the equivalence of the passwords aa and bb as follows:

  • two passwords aa and bb are equivalent if there is a letter, that exists in both aa and bb;
  • two passwords aa and bb are equivalent if there is a password cc from the list, which is equivalent to both aa and bb.

If a password is set in the system and an equivalent one is applied to access the system, then the user is accessed into the system.

For example, if the list contain passwords "a", "b", "ab", "d", then passwords "a", "b", "ab" are equivalent to each other, but the password "d" is not equivalent to any other password from list. In other words, if:

  • admin's password is "b", then you can access to system by using any of this passwords: "a", "b", "ab";
  • admin's password is "d", then you can access to system by using only "d".

Only one password from the list is the admin's password from the testing system. Help hacker to calculate the minimal number of passwords, required to guaranteed access to the system. Keep in mind that the hacker does not know which password is set in the system.

一名未知的黑客想要获取 AtForces 测试系统的管理员密码,从而提前获取下一场比赛的题目。为此,他潜入管理员办公室,窃取了一张写有 nn 个密码的纸条——每个密码均为仅由小写拉丁字母组成的字符串。

黑客回到家后,开始为入侵 AtForces 做准备。他发现该系统中仅包含这张窃取列表中的密码,并且系统对两个密码 aa 和 bb 的“等价性”定义如下:

  • 若存在某个字母,它同时出现在 aa 和 bb 中,则称密码 aa 与 bb 等价;
  • 若存在列表中的某个密码 cc,使得 cc 同时与 aa 和 bb 等价,则称 aa 与 bb 等价。

若系统中设置的密码为某密码 xx,而用户输入一个与 xx 等价的密码,则该用户即可成功登录系统。

例如,若列表中包含密码 "a"、"b"、"ab"、"d",则 "a"、"b"、"ab" 彼此等价,但 "d" 与列表中其他任何密码均不等价。换言之:

  • 若管理员密码为 "b",则可使用 "a"、"b" 或 "ab" 中任意一个密码登录系统;
  • 若管理员密码为 "d",则只能使用 "d" 登录系统。

列表中恰好有一个密码是测试系统中实际设置的管理员密码。请帮助黑客计算:为保证一定能够登录系统,他至少需要尝试多少个密码?注意,黑客并不知道系统中实际设置的是哪一个密码。

输入格式

The first line contain integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — number of passwords in the list. Next nn lines contains passwords from the list – non-empty strings sis_i, with length at most 5050 letters. Some of the passwords may be equal.

It is guaranteed that the total length of all passwords does not exceed 10610^6 letters. All of them consist only of lowercase Latin letters.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示密码列表中密码的数量。接下来的 nn 行每行包含列表中的一个密码——即非空字符串 sis_i,其长度至多为 5050 个字母。某些密码可能相同。

保证所有密码的总长度不超过 10610^6 个字母。所有密码均由小写拉丁字母组成。

输出格式

In a single line print the minimal number of passwords, the use of which will allow guaranteed to access the system.

在一行中输出能够保证访问系统的最少密码数量。

输入输出样例

  • 输入#1

    4
    a
    b
    ab
    d

    输出#1

    2
  • 输入#2

    3
    ab
    bc
    abc

    输出#2

    1
  • 输入#3

    1
    codeforces

    输出#3

    1

说明/提示

In the second example hacker need to use any of the passwords to access the system.

在第二个例子中,黑客需要使用任意一个密码来访问系统。

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

首页