/* This question requires us to find a Lexicographic Order. The order given by the string will limit the relative order before and after the Lexicographic Order of the letters. How can we express this limitation? We notice that this one is followed by another, only the previous one can be output. It is obviously the topological sorting, the minimum solution is to give priority to the queue. */# include <iostream> # include <cstdio> # include <string> # include <cstring> # include <algorithm> # include <vector> # include <queue> using namespace STD; const int maxn = 115; struct edge {int V; int NXT;} e [maxn * 50]; int n, l [maxn], ANS [maxn], orz; int head [maxn], CNT, Du [maxn]; char Sb [maxn] [maxn]; priority_que UE <int, vector <int>, greater <int> q; int read () {char CH = getchar (); int x = 0, F = 1; while (! (CH> = '0' & Ch <= '9') {If (CH = '-') F =-1; CH = getchar ();}; while (CH> = '0' & Ch <= '9') {x = x * 10 + (CH-'0'); CH = getchar ();}; return x * F;} void ins (int u, int v) {CNT ++; E [CNT]. V = V; E [CNT]. NXT = head [u]; head [u] = CNT;} void build () {Int J; For (INT I = 2; I <= N; I ++) {j = 1; while (j <= L [I-1] & J <= L [I] & SB [I] [J] = Sb [I-1] [J]) J + +; If (j> L [I-1] | j> L [I] | Sb [I] [J] = Sb [I-1] [J]) continue; ins (SB [I-1] [J]-'A ', SB [I] [J]-'A'); Du [SB [I] [J]-'a'] ++ ;}} bool TOPO () {int U, to; For (INT I = 0; I <26; I ++) {If (! Du [I]) Q. Push (I);} while (! Q. empty () {ans [++ orz] = Q. top (); q. pop (); U = ans [orz]; for (INT I = head [u]; I; I = E [I]. NXT) {to = E [I]. v; Du [to] --; If (! Du [to]) {q. push (to) ;}}return orz = 26;} int main () {freopen ("lexicographical. in "," r ", stdin); freopen (" lexicographical. out "," W ", stdout); n = read (); For (INT I = 1; I <= N; I ++) {scanf (" % s ", SB [I] + 1); L [I] = strlen (SB [I] + 1);} build (); If (! Topo () cout <"impossible"; else {for (INT I = 1; I <= 26; I ++) {char TMP = ans [I] + 'a'; cout <TMP ;}} return 0 ;}
Day8 lexicographic orders of prosperous simulation games