Runtime error for the given problem

K. Dependency Problems
We bought a brand new computer and now we would like to install an operating system. The only problem is that our chosen operating system consists of many packages and they cannot be installed in an arbitrary order. E.g. you cannot install the package tuxracer, which depends on the package libSDL, before you install libSDL. But libSDL can depend on another packages and so on. The packages may only be installed one at a time. You may install a package only if you already installed all packages it depends on. Your task is to determine how many packages can be installed on our computer.
The input contains a single line for each available package. The line for each package P begins with the name of the package. The name of each package is a non-empty string of printable characters containing no spaces (length doesn’t exceed 100). Following the name of the package P is the dependency list of P. The dependency list is simply a list of names of packages that P depends on, separated by spaces. A whitespace followed by a single 0 (zero) is at the end of each line. You may assume that no package has the name ‘0’. The size of the input doesn’t exceed 512 kilobytes.

The output consists of one number – the maximum number of packages that may be installed on the computer.

a b c b 0

b c 0

c 0

d e f 0

e f 0

f e 0

g h 0



Ideone link for the code

Could anyone please explain why am i getting a runtime error