falling_frost's blog

By falling_frost, 22 months ago, In English

ok, so I am working on a TREE problem and I encountered this piece of code and I am NOT able to understand what it is doing.

while taking the edges ( u-v ), it's going in a "add" function and the function is doing this :

void add(int x,int y) { e[idx]=y; ne[idx]=h[x]; h[x]=idx++; }

where idx is initialized to 0.

so my input was : 10 2 4 2 1 5 7 3 10 8 6 6 1 1 3 4 7 9 6

and after i print the 'e' , 'ne' , 'h' array:

e = 4 2 1 2 7 5 10 3 6 8 1 ne = -1 -1 0 -1 -1 -1 -1 -1 -1 -1 9 h = 0 12 2 13 14 4 17 15 8 16 7

totally confused.

Full text and comments »

  • Vote: I like it
  • +10
  • Vote: I do not like it