This problem is in Contest(s) below:
Contest 1337:2019好嗨哟
Contest 1332:2019小六训练题集
Contest 1345:数论的题2
Contest 1350:树的相关问题