結果

問題 No.806 木を道に
ユーザー ntudantuda
提出日時 2023-12-31 21:09:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 119,548 KB
最終ジャッジ日時 2023-12-31 21:09:57
合計ジャッジ時間 7,585 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 36 ms
53,460 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
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 -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 143 ms
88,608 KB
testcase_25 AC 172 ms
95,092 KB
testcase_26 AC 109 ms
83,436 KB
testcase_27 AC 219 ms
119,548 KB
testcase_28 AC 81 ms
76,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
UV = [list(map(int, input().split())) for _ in range(N - 1)]
D = [0] * N
E = [[] for _ in range(N)]
for u, v in UV:
    u -= 1
    v -= 1
    E[u].append(v)
    E[v].append(u)

def bfs(a):
    q = [a]
    cnt = 0
    nv = [True] * N
    nv[a] = False
    while q:
        q2 = []
        lastq = q[:]
        while q:
            x = q.pop(-1)
            for y in E[x]:
                if nv[y]:
                    nv[y] = False
                    q2.append(y)
        q, q2 = q2, q
        cnt += 1
    return (cnt, lastq)

cnt, lastq = bfs(0)
cnt, lastq = bfs(lastq[0])
print(N - cnt)
0