module md contains end module module djset_md private type,public::DJSet integer::n integer,allocatable::upper(:) contains procedure::build=>build_ procedure::root=>root_ procedure::setUnion=>setUnion_ end type contains subroutine build_(o,n_) implicit none integer::i,j,k class(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 class(DJSet)::o integer::x,res if(o%upper(x)<0)then res=x else o%upper(x)=o%root(o%upper(x)) res=o%upper(x) end if end function subroutine setUnion_(o,x,y) implicit none class(DJSet)::o integer::x,y x=root_(o,x) y=root_(o,y) if(x==y)return if(o%upper(x)