結果

問題 No.1221 木 *= 3
ユーザー Kiri8128Kiri8128
提出日時 2020-07-23 02:31:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 33,792 KB
最終ジャッジ日時 2024-04-27 13:56:02
合計ジャッジ時間 11,332 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_tree(E):
    NN = len(E) + 1
    P = [-1 for i in range(NN)]
    def par(a):
        L = []
        while P[a] >= 0:
            L.append(a)
            a = P[a]
        for l in L:
            P[l] = a
        return a
    def unite(a, b):
        if par(a) != par(b):
            if P[par(b)] >= P[par(a)]:
                if P[par(b)] == P[par(a)]: P[par(a)] -= 1
                P[par(b)] = par(a)
            else:
                P[par(a)] = par(b)
    for a, b in E:
        if not 0 <= a < NN: return False
        if not 0 <= b < NN: return False
        if par(a) == par(b):
            return False
        unite(a, b)
    return True

N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
X = []
for i in range(N-1):
    x, y = map(int, input().split())
    X.append((x-1, y-1))

assert 1 <= N <= 10 ** 5
assert len(A) == N
assert len(B) == N
for a in A:
    assert - 10 ** 9 <= a <= 10 ** 9
for b in B:
    assert - 10 ** 9 <= b <= 10 ** 9

assert is_tree(X)
0