博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #290 (Div. 2) C. Fox And Names dfs
阅读量:5905 次
发布时间:2019-06-19

本文共 2040 字,大约阅读时间需要 6 分钟。

C. Fox And Names

题目连接:

Description

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 in lexicographical 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 si and 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 Input

3

rivest

shamir

adleman

Sample Output

bcdefghijklmnopqrsatuvwxyz

Hint

题意

给你n个串,然后让你输出一个字符串,使得根据这个字符串的先后顺序排序的n个串

和给你的顺序是一样的

题解:

每两个串相比较,只需要一对字符不一样

记录一下是哪一对,然后再dfs一波就好了

注意坑点:

有可能两个串只有长度不一样

形成环

代码

#include
using namespace std;string s[120];vector
G[30];int flag = 0;int ran[40];int vis[120],used[120];int tot = 0;void solve(int x){ for(int i=0;i
>s[i]; for(int i=0;i

转载地址:http://kkcpx.baihongyu.com/

你可能感兴趣的文章
安装gulp及相关插件
查看>>
如何在Linux用chmod来修改所有子目录中的文件属性?
查看>>
Hyper-V 2016 系列教程30 机房温度远程监控方案
查看>>
笔记:认识.NET平台
查看>>
SCCM 2016 配置管理系列(Part8)
查看>>
我的友情链接
查看>>
python基础教程_学习笔记19:标准库:一些最爱——集合、堆和双端队列
查看>>
javascript继承方式详解
查看>>
lnmp环境搭建
查看>>
自定义session扫描器精确控制session销毁时间--学习笔记
查看>>
PHP队列的实现
查看>>
单点登录加验证码例子
查看>>
[T-SQL]从变量与数据类型说起
查看>>
occActiveX - ActiveX with OpenCASCADE
查看>>
BeanUtils\DBUtils
查看>>
python模块--os模块
查看>>
Java 数组在内存中的结构
查看>>
《关爱码农成长计划》第一期报告
查看>>
学习进度表 04
查看>>
谈谈javascript中的prototype与继承
查看>>