結果

問題 No.994 ばらばらコイン
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-21 21:41:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 540 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 125,568 KB
最終ジャッジ日時 2024-04-17 07:31:05
合計ジャッジ時間 4,892 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 216 ms
124,160 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 214 ms
108,160 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 47 ms
53,632 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 45 ms
53,120 KB
testcase_17 AC 45 ms
53,376 KB
testcase_18 AC 45 ms
53,632 KB
testcase_19 WA -
testcase_20 AC 46 ms
53,376 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N, M = map(int, input().split())
d = [set() for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)

queue=deque([1])
vs = set([1])
vs_bfs = list()
parents = [0] * (N+1)
dist = [0] * (N+1)
while queue:
    v = queue.popleft()
    vs_bfs.append(v)
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)
        dist[u] = dist[v] + 1

if N < M:
    print(-1)
else:
    print(max(dist))
0