Home STD Contest Notification Clarification Problems Ranklist Status Print Sign Out

Find the Shortest Common Superstring

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 295    Accepted Submission(s): 37


Problem Description
The shortest common superstring of 2 strings S1 and S2 is a string S with the minimum number of characters which contains both S1 and S2 as a sequence of consecutive characters. For instance, the shortest common superstring of ˇ°albaˇ± and ˇ°bacauˇ± is ˇ°albacauˇ±.
Given two strings composed of lowercase English characters, find the length of their shortest common superstring.
 

Input
The first line of input contains an integer number T, representing the number of test cases to follow. Each test case consists of 2 lines. The first of these lines contains the string S1 and the second line contains the string S2. Both of these strings contain at least 1 and at most 1.000.000 characters.
 

Output
For each of the T test cases, in the order given in the input, print one line containing the length of the shortest common superstring.
 

Sample Input
2 alba bacau resita mures
 

Sample Output
7 8
 

Author
Mugurel Ionut Andreica
 

Statistic | Submit | Clarifications | Back