D. Harmonious Graph(Codeforces Round #600 (Div. 2))(并查集+思维)

NoSuchKey