結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 👑 tatt61880tatt61880
提出日時 2021-02-25 00:32:07
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 160,096 KB
実行使用メモリ 14,316 KB
最終ジャッジ日時 2023-10-14 17:25:23
合計ジャッジ時間 4,564 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 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,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 14 ms
4,864 KB
testcase_14 AC 14 ms
4,684 KB
testcase_15 AC 15 ms
4,752 KB
testcase_16 AC 14 ms
4,740 KB
testcase_17 AC 14 ms
4,616 KB
testcase_18 AC 39 ms
6,896 KB
testcase_19 AC 42 ms
6,616 KB
testcase_20 AC 63 ms
8,556 KB
testcase_21 AC 102 ms
11,052 KB
testcase_22 AC 135 ms
13,104 KB
testcase_23 AC 145 ms
14,116 KB
testcase_24 AC 137 ms
14,316 KB
testcase_25 AC 144 ms
14,140 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"))
	
	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