結果
| 問題 |
No.556 仁義なきサルたち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-15 00:31:11 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,544 bytes |
| コンパイル時間 | 291 ms |
| コンパイル使用メモリ | 33,912 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 22:39:07 |
| 合計ジャッジ時間 | 1,071 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
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)<o%upper(y).or.(o%upper(x)==o%upper(y).and.x<y))then
x=xor(x,y)
y=xor(x,y)
x=xor(x,y)
end if
o%upper(y)=o%upper(x)+o%upper(y)
o%upper(x)=y
end subroutine
subroutine test
print*,"fuck"
end subroutine
end module
program main
use djset_md
implicit none
integer::n,m,i,j,k,a,b
type(DJSet)::ds
read(*,*)n,m
call ds%build(n)
do i=1,m
read(*,*)a,b
call ds%setUnion(a,b)
end do
do i=1,n
print*,ds%root(i)
end do
end program