結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー 👑 tatt61880tatt61880
提出日時 2023-08-14 22:56:27
言語 Kuin
(KuinC++ v.2021.9.17)
結果
RE  
実行時間 -
コード長 1,212 bytes
コンパイル時間 3,353 ms
コンパイル使用メモリ 148,464 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-05-02 11:03:15
合計ジャッジ時間 5,258 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 77 ms
6,784 KB
testcase_04 AC 12 ms
6,144 KB
testcase_05 AC 54 ms
5,376 KB
testcase_06 AC 51 ms
6,528 KB
testcase_07 AC 61 ms
5,376 KB
testcase_08 AC 51 ms
7,040 KB
testcase_09 AC 74 ms
5,376 KB
testcase_10 AC 80 ms
6,528 KB
testcase_11 AC 65 ms
6,272 KB
testcase_12 AC 44 ms
5,632 KB
testcase_13 AC 23 ms
5,376 KB
testcase_14 AC 41 ms
5,376 KB
testcase_15 RE -
testcase_16 AC 82 ms
5,760 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 38 ms
6,016 KB
testcase_19 AC 8 ms
5,888 KB
testcase_20 RE -
testcase_21 AC 28 ms
5,376 KB
testcase_22 AC 32 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var uni: UnionFind :: (#UnionFind).init(2 * n)
	
	var m: int :: cui@inputInt()
	for(1, m)
		var u: int :: cui@inputInt() - 1
		var v: int :: cui@inputInt() - 1
		do uni.unite(u, v)
	end for
	
	var arr: []int :: #[2 * n]int
	for i(0, 2 * n - 1)
		do arr[uni.size(i)] :+ 1
	end for
	
	var ans: int :: 0
	for i(1, 2 * n - 1, 2)
		do ans :+ arr[i] / i
	end for
	do ans :/ 2
	do cui@print("\{ans}\n")
	
	class UnionFind()
		var parents: []int
		+func init(n: int): UnionFind
			do me.parents :: [-1].repeat(n)
			ret me
		end func
		+func size(x: int): int
			ret -me.parents[me.root(x)]
		end func
		+func same(x: int, y: int): bool
			ret me.root(x) = me.root(y)
		end func
		+func unite(x: int, y: int): bool
			do x :: me.root(x)
			do y :: me.root(y)
			if(x = y)
				ret false
			end if
			if(me.size(x) < me.size(y))
				do me.parents[y] :+ me.parents[x]
				do me.parents[x] :: y
			else
				do me.parents[x] :+ me.parents[y]
				do me.parents[y] :: x
			end if
			ret true
		end func
		
		func root(x: int): int
			if(me.parents[x] < 0)
				ret x
			else
				do me.parents[x] :: me.root(me.parents[x])
				ret me.parents[x]
			end if
		end func
	end class
end func
0