[code]#include#includeusingnamespacestd;#define M 1000001intnum[M],rote[M],Maxstep;voidinit(intMax){for(inti=0;i=num[b]){num[a]+=num[b];rote[b]=rote[a];Maxstep=Maxstep>num[a]?Maxstep:num[a];}else{num[b]+=num[a];rote[a]=rote[b];Maxstep=Maxstep>num[b]?Maxste