Rosetta Problems

みさわさんの根付き木

https://atcoder.jp/contests/jag2016-domestic/tasks/jag2016secretspring_c