#x1034. CF590E Birthday

    ID: 5973 远端评测题 3000ms 512MiB 尝试: 4 已通过: 1 难度: 10 上传者: 标签>图论最小路径覆盖字符串AC自动机3200

CF590E Birthday

Birthday

题面翻译

  • 给定 nn 个仅包含 a,b 的字符串,保证它们两两不同。
  • 你需要去掉尽可能少的字符串,使得剩下的字符串中不存在某一个串是另一个串的子串。
  • n750n \le 750i=1nsi107\sum_{i=1}^n |s_i| \le 10^7

题目描述

Today is birthday of a Little Dasha — she is now 8 years old! On this occasion, each of her n n friends and relatives gave her a ribbon with a greeting written on it, and, as it turned out, all the greetings are different. Dasha gathered all the ribbons and decided to throw away some of them in order to make the remaining set stylish. The birthday girl considers a set of ribbons stylish if no greeting written on some ribbon is a substring of another greeting written on some other ribbon. Let us recall that the substring of the string s s is a continuous segment of s s .

Help Dasha to keep as many ribbons as possible, so that she could brag about them to all of her friends. Dasha cannot rotate or flip ribbons, that is, each greeting can be read in a single way given in the input.

输入格式

The first line of the input contains integer n n ( 1<=n<=750 1<=n<=750 ) — the number of Dasha's relatives and friends.

Each of the next n n lines contains exactly one greeting. Each greeting consists of characters 'a' and 'b' only.

The total length of all greetings won't exceed 10000000 10000000 characters.

输出格式

In the first line print the maximum size of the stylish set. In the second line print the numbers of ribbons involved in it, assuming that they are numbered from 1 1 to n n in the order they appear in the input. If there are several stylish sets of the maximum size, print any of them.

样例 #1

样例输入 #1

5
abab
aba
aabab
ababb
bab

样例输出 #1

2
2 5

提示

In the sample, the answer that keeps ribbons 3 and 4 is also considered correct.