結果
| 問題 |
No.556 仁義なきサルたち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-15 00:04:58 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 1,239 bytes |
| コンパイル時間 | 1,062 ms |
| コンパイル使用メモリ | 33,792 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 22:38:29 |
| 合計ジャッジ時間 | 1,123 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
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
res=root(o,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)<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
end module
program main
use djset_md
implicit none
integer::n,m,i,j,k,a,b
type(DJSet)::ds
read(*,*)n,m
call build(ds,n)
do i=1,m
read(*,*)a,b
call setUnion(ds,a,b)
end do
do i=1,n
print*,root(ds,i)
end do
end program