#DSU0000056. Các mật khẩu tương đương (Secret Passwords)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các mật khẩu tương đương (Secret Passwords)
Secret Passwords
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given passwords. Each password is a nonempty string of lowercase English letters. Different entries in the list are not necessarily distinct.
Two passwords are directly linked if they share at least one letter, regardless of its position. This relation extends through chains: if the first password is linked to a second and the second is linked to a third, then the first and third belong to the same group even if they share no letter themselves.
The secret password is known to be one of the listed passwords. Trying a password lets you cover its entire linked group. Determine the minimum number of attempts required to cover the group of the secret password, whichever listed password it happens to be.
Input
The first line contains , followed by nonempty password strings.
Output
Print the minimum number of passwords to try.
Subtasks
- Subtask 1 (20 points): , ; ; every character is a lowercase letter
a–z. - Subtask 2 (30 points): , ; ; every character is a lowercase letter
a–z. - Subtask 3 (50 points): , ; ; every character is a lowercase letter
a–z.
Examples
Input
4
a
b
ab
d
Output
2
Explanation
Password ab connects a and b, producing one equivalence class {a,b,ab}; d is in another. One representative from each class suffices, so the answer is 2.