結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 26 ms
10,624 KB
testcase_03 AC 26 ms
10,624 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 26 ms
10,752 KB
testcase_06 AC 26 ms
10,752 KB
testcase_07 AC 25 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 27 ms
10,624 KB
testcase_10 WA -
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 42 ms
10,624 KB
testcase_13 AC 63 ms
12,544 KB
testcase_14 AC 58 ms
12,416 KB
testcase_15 AC 56 ms
12,544 KB
testcase_16 AC 66 ms
12,416 KB
testcase_17 AC 68 ms
12,544 KB
testcase_18 AC 143 ms
16,128 KB
testcase_19 WA -
testcase_20 AC 230 ms
19,584 KB
testcase_21 AC 360 ms
24,192 KB
testcase_22 AC 400 ms
27,904 KB
testcase_23 AC 434 ms
28,800 KB
testcase_24 AC 442 ms
28,800 KB
testcase_25 AC 431 ms
28,928 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)
    
    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