1263D.md (2483B)
1 Source: https://codeforces.com/problemset/problem/1263/D 2 3 D. Secret Passwords 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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 $n$ passwords — strings, consists of small Latin letters. 22 23 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 $a$ and $b$ as follows: 24 25 * two passwords $a$ and $b$ are equivalent if there is a letter, that exists in both $a$ and $b$; 26 * two passwords $a$ and $b$ are equivalent if there is a password $c$ from the list, which is equivalent to both $a$ and $b$. 27 28 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. 29 30 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: 31 32 * admin's password is "b", then you can access to system by using any of this passwords: "a", "b", "ab"; 33 * admin's password is "d", then you can access to system by using only "d". 34 35 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. 36 37 Input 38 39 The first line contain integer $n$ ($1 \le n \le 2 \cdot 10^5$) — number of passwords in the list. Next $n$ lines contains passwords from the list – non-empty strings $s_i$, with length at most $50$ letters. Some of the passwords may be equal. 40 41 It is guaranteed that the total length of all passwords does not exceed $10^6$ letters. All of them consist only of lowercase Latin letters. 42 43 Output 44 45 In a single line print the minimal number of passwords, the use of which will allow guaranteed to access the system. 46 47 Examples 48 49 Input 50 51 ``` 52 4 53 a 54 b 55 ab 56 d 57 ``` 58 59 Output 60 61 ``` 62 2 63 ``` 64 65 Input 66 67 ``` 68 3 69 ab 70 bc 71 abc 72 ``` 73 74 Output 75 76 ``` 77 1 78 ``` 79 80 Input 81 82 ``` 83 1 84 codeforces 85 ``` 86 87 Output 88 89 ``` 90 1 91 ``` 92 93 Note 94 95 In the second example hacker need to use any of the passwords to access the system.