結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 2000 Ekiben2000 Ekiben
提出日時 2024-06-20 17:22:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,928 KB
最終ジャッジ日時 2024-06-20 17:22:07
合計ジャッジ時間 5,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 29 ms
10,880 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 WA -
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 32 ms
10,752 KB
testcase_13 AC 75 ms
12,416 KB
testcase_14 AC 69 ms
12,544 KB
testcase_15 AC 70 ms
12,544 KB
testcase_16 AC 71 ms
12,544 KB
testcase_17 AC 74 ms
12,544 KB
testcase_18 AC 157 ms
16,256 KB
testcase_19 WA -
testcase_20 AC 245 ms
19,584 KB
testcase_21 AC 374 ms
24,448 KB
testcase_22 AC 458 ms
28,032 KB
testcase_23 AC 515 ms
28,800 KB
testcase_24 AC 471 ms
28,928 KB
testcase_25 AC 513 ms
28,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def find(parent, i):
    if parent[i] == i:
        return i
    else:
        return find(parent, parent[i])

def union(parent, rank, x, y):
    xroot = find(parent, x)
    yroot = find(parent, y)
    
    if xroot != yroot:
        if rank[xroot] < rank[yroot]:
            parent[xroot] = yroot
        elif rank[xroot] > rank[yroot]:
            parent[yroot] = xroot
        else:
            parent[yroot] = xroot
            rank[xroot] += 1

def ist(N, edges):
    parent = list(range(N))
    rank = [0] * N
    
    for u, v in edges:
        if find(parent, u) == find(parent, v):
            return False
        else:
            union(parent, rank, u, v)
    
    root = find(parent, 0)
    for i in range(1, N):
        if find(parent, i) != root:
            return False
    return True
N = int(input().strip())
edges = []
for _ in range(N - 1):
    u, v = map(int, input().strip().split())
    edges.append((u, v))
if ist(N, edges):
    print("Bob")
else:
    print("Alice")
0