# Can anyone help me with Heights of Students from TCS Mockvita 2018 Contest?

Hello friends can someone tell me how to approach this problem ?

One way could be we make a directed graph with A->B signifying that A is taller than B
then we do a topological sort of the nodes and then count the number of elements such that they do not have an edge between an element in front of them or behind, in the topologically sorted sequences
for example in the test case, the topologically sorted sequence would be
D->C->B->A->E->F->G->H
here A doesnâ€™t have an edge to B and B doesnâ€™t have an edge to A hence they both fell into this catogory
I am not sure of this method. It might work

1 Like

@sonu_628 as I am not good at implementing graphs can you help me with code also.Thanks

here is what I tried but I am not able to get it working https://ideone.com/LRKpRA

@harrypotter0 saw your code, the n and m are integers separated by comma so cin wont work. another thing when you initized graph the total of vertice are n rather m. i am sure about the implementation of topological sort

I changed input from 8,3 to 8 3 for it to work and correct graph initialization https://ideone.com/suKL4o

okay thanks for this but still the answer is not correct.