Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Model these equalities as edges of a graph.
Group each connected component of the graph and assign each node of this component to the node with the lowest lexicographically character.
Finally convert the string with the precalculated information.