結果

問題 No.1153 ねこちゃんゲーム
ユーザー Kiri8128Kiri8128
提出日時 2020-07-13 23:13:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,700 KB
実行使用メモリ 100,824 KB
最終ジャッジ日時 2024-04-26 05:19:54
合計ジャッジ時間 21,000 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 43 ms
51,968 KB
testcase_02 WA -
testcase_03 AC 61 ms
70,272 KB
testcase_04 WA -
testcase_05 AC 66 ms
70,656 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 452 ms
99,288 KB
testcase_09 WA -
testcase_10 AC 468 ms
99,576 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 470 ms
100,344 KB
testcase_14 WA -
testcase_15 AC 490 ms
99,684 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 463 ms
99,564 KB
testcase_19 WA -
testcase_20 AC 465 ms
99,712 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 448 ms
99,064 KB
testcase_24 WA -
testcase_25 AC 455 ms
99,420 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 483 ms
100,352 KB
testcase_29 WA -
testcase_30 AC 481 ms
100,340 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 408 ms
98,780 KB
testcase_34 WA -
testcase_35 AC 426 ms
99,192 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# assertion
N, M = map(int, input().split())
assert 1 <= N <= 200000
assert 1 <= M <= 200000

def is_tree(E):
    NNNNN = len(E) + 1
    P = [-1 for i in range(NNNNN)]
    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 < N: return False
        if not 0 <= b < N: return False
        if par(a) == par(b):
            return False
        unite(a, b)
    return True

A = [int(a) - 1 for a in input().split()]
assert len(A) == M
for a in A:
    assert 0 <= a < N
    
E = [[int(a) - 1 for a in input().split()] for _ in range(N - 1)]
assert is_tree(E)
print(-1, -1)
0