post-comp 2014.1.c.b: complete rewrite using graphs

Completely rewrote the algorithm to construct a graph where each node
represents a single letter (or rather a sequence of identical letters),
each edge is a pair of adjacent distinct letters, and where one checks
for only one incoming and outgoing edge per node (apart from
"self-edges" linking back to the same node). Additionally one has to
check for no cycles in the graph.

TODO: Test this solution on the Google CodeJam site.