Longest Spanning Substrings Problem Code: LNGSUB Codechef Solutions
Longest Spanning Substrings Problem Code: LNGSUBSubmit
Read problem statements in Mandarin, Bengali, Russian, and Vietnamese as well.
You are given strings . Consider a complete undirected graph with vertices (numbered through ), in which the weight of an edge between vertices and is equal to the length of the longest common substring of and .
Find the maximum possible weight of a spanning tree of this graph.
Input Format
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- lines follow. For each valid , the -th of these lines contains a single string .
Output Format
For each test case, print a single line containing one integer --- the maximum weight of a spanning tree.
Constraints
- for each valid , contains only lowercase English letters
- the sum of lengths of all strings over all test cases does not exceed
Subtasks
Subtask #1 (10 points): the sum of lengths of all strings over all test cases does not exceed
Subtask #2 (20 points): the sum of lengths of all strings over all test cases does not exceed
Subtask #3 (70 points): original constraints
Sample Input 1
3
3
bbcab
aa
aab
3
bbc
bcaa
abb
3
aa
acc
abbca
Sample Output 1
4
4
2
Explanation
Example case 1: The strings have a longest common substring with length , and the strings have a longest common substring with length . The spanning tree which contains the edges and has the maximum weight .
Comments
Post a Comment