結果

問題 No.806 木を道に
ユーザー terasaterasa
提出日時 2022-06-02 16:33:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 93,288 KB
最終ジャッジ日時 2023-10-21 01:12:14
合計ジャッジ時間 7,001 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,712 KB
testcase_01 AC 43 ms
55,712 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 45 ms
55,712 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 40 ms
55,712 KB
testcase_08 AC 41 ms
55,712 KB
testcase_09 AC 41 ms
55,712 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 90 ms
82,972 KB
testcase_25 AC 98 ms
85,364 KB
testcase_26 AC 81 ms
80,336 KB
testcase_27 AC 118 ms
93,288 KB
testcase_28 AC 58 ms
70,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


N = int(input())
E = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)


def search(s):
    dq = deque([s])
    INF = 1 << 30
    cost = [INF] * N
    cost[s] = 0

    while len(dq) > 0:
        v = dq.popleft()
        for d in E[v]:
            if cost[d] > cost[v] + 1:
                cost[d] = cost[v] + 1
                dq.append(d)
    return cost


c = search(0)
s = 0
for i in range(N):
    if c[s] < c[i]:
        s = i
c = search(s)
t = 0
for i in range(N):
    if c[t] < c[i]:
        t = i
print(N - 1 - c[t])
0