結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー 小野寺健小野寺健
提出日時 2021-04-27 17:00:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 418 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 10,796 KB
実行使用メモリ 41,548 KB
最終ジャッジ日時 2023-09-20 17:42:49
合計ジャッジ時間 22,403 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,740 KB
testcase_01 AC 16 ms
7,740 KB
testcase_02 AC 15 ms
7,736 KB
testcase_03 AC 15 ms
7,696 KB
testcase_04 AC 32 ms
8,532 KB
testcase_05 AC 88 ms
10,668 KB
testcase_06 AC 91 ms
10,896 KB
testcase_07 AC 56 ms
9,736 KB
testcase_08 AC 105 ms
11,332 KB
testcase_09 AC 93 ms
10,932 KB
testcase_10 AC 90 ms
10,816 KB
testcase_11 AC 79 ms
10,508 KB
testcase_12 AC 70 ms
10,232 KB
testcase_13 AC 21 ms
8,136 KB
testcase_14 AC 903 ms
34,456 KB
testcase_15 AC 864 ms
33,036 KB
testcase_16 AC 797 ms
31,328 KB
testcase_17 AC 577 ms
25,720 KB
testcase_18 AC 1,019 ms
36,736 KB
testcase_19 AC 1,244 ms
41,424 KB
testcase_20 AC 1,226 ms
41,504 KB
testcase_21 AC 1,173 ms
41,420 KB
testcase_22 AC 1,208 ms
41,408 KB
testcase_23 AC 1,172 ms
41,480 KB
testcase_24 AC 1,163 ms
41,360 KB
testcase_25 AC 1,179 ms
41,324 KB
testcase_26 AC 1,186 ms
41,376 KB
testcase_27 AC 1,172 ms
41,428 KB
testcase_28 AC 1,186 ms
41,468 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 797 ms
36,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

V = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    V[a-1].append(b-1)
    V[b-1].append(a-1)
    
def dfs(prev, i, n):
    if len(V[i]) == 1 and V[i][0] == prev:
        return (n, i)
    rtn = (-1, -1)
    for j in V[i]:
        if j != prev:
            rtn = max(rtn, dfs(i, j, n+1))
    return rtn

n, u= dfs(-1, 0, 0)
n, v = dfs(-1, u, 0)

print(2*(N-1)-n)
0