当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6138:Fleet of the Eternal Throne

题目描述
> The Eternal Fleet was built many centuries ago before the time of Valkorion by an unknown race on the planet of Iokath. The fate of the Fleet's builders is unknown but their legacy would live on. Its first known action was in the annihilation of all life in Wild Space. It spread across Wild Space and conquered almost every inhabited world within the region, including Zakuul. They were finally defeated by a mysterious vessel known as the Gravestone, a massive alien warship that countered the Eternal Fleet's might. Outfitted with specialized weapons designed to take out multiple targets at once, the Gravestone destroyed whole sections of the fleet with a single shot. The Eternal Fleet was finally defeated over Zakuul, where it was deactivated and hidden away. The Gravestone landed in the swamps of Zakuul, where the crew scuttled it and hid it away.
>
> — Wookieepedia

The major defeat of the Eternal Fleet is the connected defensive network. Though being effective in defensing a large fleet, it finally led to a chain-reaction and was destroyed by the Gravestone. Therefore, when the next generation of Eternal Fleet is built, you are asked to check the risk of the chain reaction.

The battleships of the Eternal Fleet are placed on a 2D plane of $n$ rows. Each row is an array of battleships. The type of a battleship is denoted by an English lowercase alphabet. In other words, each row can be treated as a string. Below lists a possible configuration of the Eternal Fleet.


aa
bbbaaa
abbaababa
abba


If in the $x$-th row and the $y$-th row, there exists a consecutive segment of battleships that looks identical in both rows (i.e., a common substring of the $x$-th row and $y$-th row), at the same time the substring is a prefix of any other row (can be the $x$-th or the $y$-th row), the Eternal Fleet will have a risk of causing chain reaction.

Given a query ($x$, $y$), you should find the longest substring that have a risk of causing chain reaction.
输入解释
The first line of the input contains an integer $T$, denoting the number of test cases.

For each test cases, the first line contains integer $n$ ($n\le10^5$).

There are $n$ lines following, each has a string consisting of lower case letters denoting the battleships in the row. The total length of the strings will not exceed $10^5$.

And an integer $m$ ($1\le m\le100$) is following, representing the number of queries.

For each of the following $m$ lines, there are two integers $x, y$, denoting the query.
输出解释
You should output the answers for the queries, one integer per line.
输入样例
1
3
aaa
baaa
caaa
2
2 3
1 2
输出样例
3
3
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6138

最后修改于 2020-10-25T23:28:41+00:00 由爬虫自动更新

共提交 2

通过率 50.0%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)