結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 👑 tatt61880tatt61880
提出日時 2021-02-25 00:20:16
言語 Kuin
(KuinC++ v.2021.9.17)
結果
WA  
実行時間 -
コード長 1,220 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 158,200 KB
実行使用メモリ 14,216 KB
最終ジャッジ日時 2023-10-14 17:25:10
合計ジャッジ時間 6,600 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 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 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 14 ms
4,784 KB
testcase_14 AC 15 ms
4,760 KB
testcase_15 AC 15 ms
4,724 KB
testcase_16 AC 15 ms
4,816 KB
testcase_17 AC 14 ms
4,652 KB
testcase_18 AC 44 ms
6,588 KB
testcase_19 AC 46 ms
6,584 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 195 ms
14,052 KB
testcase_24 AC 172 ms
14,216 KB
testcase_25 AC 194 ms
14,188 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)
			if(^a[i] <> 0 & ^a[i] <> 2)
				do ans :: false
			end if
		end for
	end if
	
	do cui@print(ans ?("Bob\n", "Alice\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