graph - sorting algorithm for the following? -


so, trying solve following problem:

http://codeforces.com/contest/510/problem/b

i solve way:

  1. create graph g each vertex represents letter alphabet.
  2. insert directed edge v1 v2 g iff there exist 2 words in given sequence such w1 = prefix v1 suffix1, w2 = prefix v2 suffix2 , w1 precedes w2 in given sequence. should figure out how make step efficient. believe can done in o(sum on length of each word)
  3. return true if g can sorted topologicaly.

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -