module md contains end module module djset_md type DJSet integer::n integer,allocatable::upper(:) end type contains subroutine build(o,n_) type(DJSet)::o integer::n_ o%n=n_ allocate(o%upper(o%n)) do i=1,o%n o%upper(i)=-1 end do end subroutine recursive function root(o,x)result(res) implicit none type(DJSet)::o integer::x,res if(o%upper(x)<0)then res=x else o%upper(x)=root(o,o%upper(x)) res=o%upper(x) end if end function subroutine setUnion(o,x,y) integer::x,y type(DJSet)::o x=root(o,x) y=root(o,y) if(x==y)return if(o%upper(x)