結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー terasaterasa
提出日時 2022-05-27 00:12:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,766 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 76,724 KB
最終ジャッジ日時 2023-10-20 19:36:18
合計ジャッジ時間 5,072 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,592 KB
testcase_01 AC 43 ms
55,592 KB
testcase_02 AC 43 ms
55,592 KB
testcase_03 AC 44 ms
55,592 KB
testcase_04 AC 43 ms
55,592 KB
testcase_05 AC 43 ms
55,592 KB
testcase_06 AC 43 ms
55,592 KB
testcase_07 AC 44 ms
55,592 KB
testcase_08 AC 43 ms
55,592 KB
testcase_09 AC 45 ms
55,592 KB
testcase_10 WA -
testcase_11 AC 45 ms
55,592 KB
testcase_12 AC 45 ms
55,592 KB
testcase_13 AC 83 ms
76,004 KB
testcase_14 AC 71 ms
76,016 KB
testcase_15 AC 71 ms
76,016 KB
testcase_16 AC 72 ms
76,012 KB
testcase_17 AC 69 ms
76,012 KB
testcase_18 AC 82 ms
76,172 KB
testcase_19 WA -
testcase_20 AC 102 ms
76,312 KB
testcase_21 AC 117 ms
76,540 KB
testcase_22 AC 129 ms
76,688 KB
testcase_23 AC 131 ms
76,724 KB
testcase_24 AC 123 ms
76,720 KB
testcase_25 AC 137 ms
76,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict, Counter
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


class UnionFind:
    def __init__(self, N):
        self.N = N
        self.par = [-1] * N

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if x > y:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.par[self.find(x)]

    def roots(self):
        return [i for i in range(self.N) if self.par[i] < 0]

    def members(self, x):
        p = self.find(x)
        return [i for i in range(self.N) if self.find(i) == p]


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


N = int(input())
uf = UnionFind(N)
for _ in range(N - 1):
    u, v = map(int, input().split())
    uf.unite(u, v)
print('Alice' if len(uf.roots()) > 1 else 'Bob')
0