educative.io

Check if a directed graph is tree or not solution question

For checkConnected method (1st solution), the default source used is 0. Does that mean for a tree, the mother vertex must be 0? becuase for the following scenario, the first solution will not work if the mother vertex is not 0.

edge(1, 0)
edge(1, 2)

Hi @Manxiang_Zhang,
Welcome to the Discuss community!

In the provided graph implementation, node 0 is considered as the root node. It was not mentioned in the requirement of this challenge before, and we’ve added this to the challenge lesson as follows:

Please keep in mind the following points:

  1. The graph implementation creates n nodes with labels from 0 to n-1.
  2. The node with label 0 is always the root node.

Thanks for pointing this out.
Happy Learning!