Fox And Names
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.

After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted inlexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical!

She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order.

Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters:si ≠ ti. If there is no such position (i. e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters siand ti according to their order in alphabet.

Input

The first line contains an integer n (1 ≤ n ≤ 100): number of names.

Each of the following n lines contain one string namei (1 ≤ |namei| ≤ 100), the i-th name. Each name contains only lowercase Latin letters. All names are different.

Output

If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on).

Otherwise output a single word "Impossible" (without quotes).

Sample test(s)
input
`3rivestshamiradleman`
output
`bcdefghijklmnopqrsatuvwxyz`
input
`10touristpetrwjmzbmryeputonsvepifanovscottwuoooooooooooooooosubscriberrowdarktankengineer`
output
`Impossible`
input
`10petregorendagorionfeferivanilovetanyaromanovakostkadmitriyhmaratsnowbearbredorjaguarturnikcgyforever`
output
`aghjlnopefikdmbcqrstuvwxyz`
input
`7carcarecarefulcarefullybecarefuldontforgetsomethingotherwiseyouwillbehackedgoodluck`
output
`acbdefhijklmnogpqrstuvwxyz`

``` #include <bits/stdc++.h>
using    namespace    std;

][];
];
];

void    toposort(void);
int    main(void)
{
int    n;
][];
bool    flag;

cin >> n;
;i < n;i ++)
cin >> name[i];
;i < n - ;i ++)
{
;name[i][j] && name[i + ][j];j ++)
{
flag = false;
][j])
{
][j] - 'a'])
{
G[name[i][j] - ][j] - 'a'] = true;
IN[name[i + ][j] - 'a'] ++;
}
flag = true;
break;
}
}
]))
{
puts("Impossible");
;
}
}
toposort();

;
}

void    toposort(void)
{
queue<int>    que;
;
;
int    front;

;i < ;i ++)
if(!IN[i])
{
ANS[k ++] = i;
sum ++;
que.push(i);
}

while(!que.empty())
{
front = que.front();
que.pop();
;i < ;i ++)
if(G[front][i])
{
IN[i] --;
if(!IN[i])
{
ANS[k ++] = i;
que.push(i);
sum ++;
}
}
}
)
puts("Impossible");
else
{
;i < ;i ++)
printf("%c",ANS[i] + 'a');
puts("");
}

return    ;
}```

CF Fox And Names (拓扑排序)的更多相关文章

1. [CF #290-C] Fox And Names (拓扑排序)

题目链接:http://codeforces.com/contest/510/problem/C 题目大意:构造一个字母表,使得按照你的字母表能够满足输入的是按照字典序排下来. 递归建图:竖着切下来, ...

2. （CodeForces 510C） Fox And Names 拓扑排序

题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...

3. CF 213A Game（拓扑排序）

传送门 Description Furik and Rubik love playing computer games. Furik has recently found a new game tha ...

4. 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names

题目传送门 /* 给出n个字符串,求是否有一个“字典序”使得n个字符串是从小到大排序 拓扑排序 详细解释:http://www.2cto.com/kf/201502/374966.html */ #i ...

5. CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序

题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...

6. C. Fox And Names

C. Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

7. Fox And Names

Description Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce ...

8. Java排序算法——拓扑排序

package graph; import java.util.LinkedList; import java.util.Queue; import thinkinjava.net.mindview. ...

9. Codeforces Round #290 (Div. 2) C. Fox And Names dfs

C. Fox And Names 题目连接: http://codeforces.com/contest/510/problem/C Description Fox Ciel is going to ...

随机推荐

1. C#向Sql数据库插入控制

string name = textBox1.Text; int age = Convert.ToInt32(textBox2.Text.Trim()); ? null : (int?)Convert ...

2. 在表单中元素的onchange事件的兼容性问题

3. 一步一步搭建Jenkins环境

Jenkins使用经验谈1(一步一步搭建Jenkins环境)在公司使用 Jenkins 软件已经有一段时间了,走了很多弯路,但也积累了一些经验,可以和大家分享一下.我们来一起搭建Jenkins环境.首 ...

4. Introduction to Project Management(II)

Introduction The purpose of this paper is to gain an understanding of project management and to give ...

private static void syncMetaData() { var siteUrl = @"http://..."; using (var site = new SP ...

6. Sqli-labs less 43

7. usb.ids

# # List of USB ID's # # Maintained by Vojtech Pavlik <vojtech@suse.cz> # If you have any new ...

8. 吧php脚本打包成 exe程序

操作方法 :FQ哦 https://www.youtube.com/watch?v=UQ3zxqh1YXY 有很多方法可以实现 找了个外国的哥们制作的工具 可以吧文件生成很简单的一个独立EXE文件 下 ...

9. mysql主从复制 详解

转自 http://blog.csdn.net/m582445672/article/details/7731565 实践: http://shiyanjun.cn/archives/584.html ...

10. 如何写好一个UITableView

本文是直播分享的简单文字整理,直播共分为上.下两部分. 第一部分: 优酷 :http://v.youku.com/v_show/id_XMTUzNzQzMDU0NA%3Cmark%3E.html Or ...