#P7017. [CERC2013] Digraphs
[CERC2013] Digraphs
题目描述
A digraph is a graph with orientation... oh, sorry, not this time. Let's stop being nerds for a minute and talk about languages (human languages, not PHP).
Digraphs are pairs of characters that represent one phoneme (sound). For example, "ch" in English (as in "church") is a single consonant sound. The languages of Central Europe are fond of digraphs: Hungarian "sz", Czech "ch" and Polish "rz" are fine examples of them.
Digraphs are very annoying for people who do not use them natively. We will make up a letter-puzzle specifically for those people. Given a list of digraphs, construct a biggest possible square of lower case English letters such that its rows and columns do not contain any of these digraphs. This means that no two consecutive letters (read from top to bottom or from left to right) can form a digraph.
输入格式
The first line of input contains the number of test cases . The descriptions of the test cases follow:
Each test case starts with an integer , denoting the number of forbidden digraphs. The following lines contain the digraphs.
输出格式
For each test case print a square of the largest possible size which does not contain any of the digraphs. If it is possible to construct a square of size or bigger, print only a square.
Warning: Part of the example test data below was omitted for clarity. You can access full sample tests at your workstation.
题目大意
题目描述
有一些有向字母对,构造一个尽量大(最大)的方阵,使得这个方阵中任意两个相邻字母对(从左到右或从上到下)都不是这些有向字母对中的一个。
输入格式
第一行一个整数,表示数据组数。
每组数据第一行一个整数(),表示有向字母对数。
接下来行,每行个小写字母,表示一组有向字母对。
输出格式
对于每组数据,输出一个尽量大的方阵,不包含任何一个有向字母对(如果可以构造比规模更大的方阵,只需要规模就够了)。
如果有多组解,输出任意一组即可。
提示
Time limit: 2 s, Memory limit: 128 MB.