TikTok interview question

How to detect if this graph is a tree?