結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 👑 tatt61880tatt61880
提出日時 2021-03-28 08:56:13
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 2,734 ms
コンパイル使用メモリ 159,604 KB
実行使用メモリ 14,244 KB
最終ジャッジ日時 2023-10-14 18:04:02
合計ジャッジ時間 5,155 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 15 ms
4,676 KB
testcase_14 AC 15 ms
4,612 KB
testcase_15 AC 14 ms
4,872 KB
testcase_16 AC 14 ms
4,796 KB
testcase_17 AC 16 ms
4,736 KB
testcase_18 AC 44 ms
6,852 KB
testcase_19 AC 48 ms
6,552 KB
testcase_20 AC 78 ms
8,304 KB
testcase_21 AC 134 ms
10,964 KB
testcase_22 AC 177 ms
13,132 KB
testcase_23 AC 188 ms
14,244 KB
testcase_24 AC 174 ms
14,220 KB
testcase_25 AC 192 ms
14,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var uni: @UnionFind :: (#@UnionFind).init(n)
	var a: [][]int :: #[n, 0]int
	for(1, n - 1)
		var u: int :: cui@inputInt()
		var v: int :: cui@inputInt()
		do a[u] :~ [v]
		do a[v] :~ [u]
		do uni.unite(u, v)
	end for
	
	var ans: bool :: true
	if(uni.size(0) <> n)
		for i(0, n - 1)
			switch(^a[i])
			case 0
			case 2
				if(uni.size(i) <> n - 1)
					do ans :: false
					break i
				end if
			default
				do ans :: false
				break i
			end switch
		end for
	end if
	do cui@print(ans ?("Bob\n", "Alice\n"))
end func

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
0