Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Itsy's Magic Cards

Limits 1s, 512 MB

Itsy needs your help with her magic cards. Her magic cards grant her special spider-witch powers.

Unfortunately, some of the magic cards are a bit strange. Whenever they come close to each other, they react and vanish into thin air.

Itsy has N magic cards in front of her right now, and she wants to find the maximum number of cards that she can stack together without having to worry about them vanishing.


The input starts with two integers, N (0 < N < 18) and M (0 < M < 10). N represents the number of cards Itsy has in front of her.

The following M lines will contain two uppercase alphabets each representing the two cards that would react and vanish if they come to close to each other. The alphabets will always be valid (i.e. only the first N alphabets may appear in these M lines).


Print the maximum number of cards that Itsy can keep together without having to worry about the cards vanishing.


6 2

In this case, the cards A and B (and, cards B and E) cannot be chosen together. The maximum number of cards can be chosen by ignoring B.



52% Solution Ratio

alexwiceEarliest, Sep '19

yasir.nabilFastest, 0.0s

towfiq379Lightest, 0 B

bokaifShortest, 185B


Login to submit

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.