#P9664. [ICPC2021 Macao R] LCS Spanning Tree

    ID: 9026 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2021后缀自动机,SAMO2优化生成树后缀数组,SA后缀树ICPC澳门

[ICPC2021 Macao R] LCS Spanning Tree

题目描述

Given a complete undirected graph of nn vertices and nn strings s1,s2,,sns_1, s_2, \cdots, s_n, the weight of edge connecting vertices ii and jj is equal to the length of the longest common substring (LCS) between sis_i and sjs_j. Compute the maximum total weight of any spanning tree on this graph.

A substring of a string can be obtained by removing some (possibly zero) characters from the beginning and/or the end of that string. For example, maca, aca and cau are all substrings of macau, while acu is not.

输入格式

There is only one test case in each test file.

The first line of the input contains one integer nn (1n2×1061 \leq n \leq 2 \times 10^6) indicating the number of vertices and strings.

For the following nn lines, the ii-th line contains one string sis_i (1si2×1061 \le |s_i| \le 2 \times 10^6) consisting only of lowercase English letters.

It's guaranteed that the sum of lengths of all strings will not exceed 2×1062 \times 10^6.

输出格式

Output one line containing one integer indicating the answer.

4
icpc
macau
regional
contest
4
3
ababa
babab
aba
7