Rosetta Problems

Is it a tree?

https://atcoder.jp/contests/past202206-open/tasks/past202206_g