結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー NP
提出日時 2024-06-20 17:17:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 877 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,928 KB
最終ジャッジ日時 2024-06-20 17:17:43
合計ジャッジ時間 5,210 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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)
    
    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