結果

問題 No.806 木を道に
ユーザー kept1994kept1994
提出日時 2021-08-31 19:43:01
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 831 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 99,652 KB
最終ジャッジ日時 2023-08-17 07:40:00
合計ジャッジ時間 7,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,468 KB
testcase_01 AC 98 ms
71,464 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 96 ms
71,320 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 98 ms
71,308 KB
testcase_08 AC 98 ms
71,604 KB
testcase_09 AC 100 ms
71,624 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 181 ms
92,864 KB
testcase_25 AC 200 ms
99,652 KB
testcase_26 AC 153 ms
82,380 KB
testcase_27 AC 205 ms
93,484 KB
testcase_28 AC 127 ms
78,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    from collections import deque
    N = int(input())
    INF = 10 ** 16
    G = [[] for _ in range(N)]
    def bfs(edges: "List[to]", start_node: int) -> list:
        q = deque()
        dist = [INF] * len(edges)
        q.append(start_node)
        dist[start_node] = 0
        while q:
            now = q.popleft()
            for next in edges[now]:
                if dist[next] != INF:
                    continue
                q.append(next)
                dist[next] = dist[now] + 1
        return dist
    for _ in range(N - 1):
        a, b = map(int, input().split())
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)
    d = bfs(G, 0)
    i = d.index(max(d))
    dd = bfs(G, i)
    print(N - len(set(dd)))

        
if __name__ == '__main__':
    main()
0