fix leaf generation in graph2tree; fix encoding matrix in graph