Assign root vertex automatically