Short Message 2
InterviewTime limit1sMemory limit1024 MB
Given N planet names made of lowercase letters, find the shortest string that contains every name as a substring.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation, String
- Solved
- No attempts yet
Problem
The Space Research Center has identified planets, each with a name made up only of lowercase Latin letters. The researchers think that if some of these planets have intelligent life, they will reply to a message that contains the planet's name.
Sending cosmic messages is expensive, so we need a message that is as short as possible and contains all planet names as substrings.
Recall that a string is a substring of a string if can be obtained from by deleting some characters from the beginning and the end of .
Input
The first line of the input file contains the number of planets . Each of the next lines contains one planet name .
Output
Print on the single line of the output file a message made of lowercase Latin letters that contains all planet names as substrings.