結果
問題 | No.277 根掘り葉掘り |
ユーザー |
👑 ![]() |
提出日時 | 2023-01-15 12:53:51 |
言語 | PyPy3 (7.3.8) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,210 bytes |
コンパイル時間 | 277 ms |
使用メモリ | 109,664 KB |
最終ジャッジ日時 | 2023-01-15 12:54:00 |
合計ジャッジ時間 | 7,919 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 196 ms
85,900 KB |
testcase_01 | AC | 180 ms
85,960 KB |
testcase_02 | WA | - |
testcase_03 | AC | 173 ms
85,828 KB |
testcase_04 | AC | 173 ms
85,824 KB |
testcase_05 | AC | 172 ms
85,792 KB |
testcase_06 | AC | 172 ms
85,708 KB |
testcase_07 | AC | 184 ms
85,916 KB |
testcase_08 | AC | 183 ms
85,800 KB |
testcase_09 | AC | 351 ms
107,072 KB |
testcase_10 | AC | 321 ms
109,664 KB |
testcase_11 | AC | 349 ms
101,316 KB |
testcase_12 | AC | 378 ms
103,120 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
ソースコード
from typing import List, Tuple, Callable, TypeVar, Optional import sys import itertools import heapq import bisect import math from collections import deque, defaultdict from functools import lru_cache, cmp_to_key input = sys.stdin.readline if __file__ != 'prog.py': sys.setrecursionlimit(10 ** 6) def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] def readlist1(): return list(map(lambda x: int(x) - 1, input().split())) N = int(input()) E = [[] for _ in range(N)] for _ in range(N - 1): u, v = readints() u -= 1 v -= 1 E[u].append(v) E[v].append(u) R = [0] * N L = [N] * N stack = [(0, -1)] while stack: v, p = stack.pop() if v < 0: v = ~v is_leaf = True for dst in E[v]: if dst == p: continue is_leaf = False L[v] = min(L[v], L[dst] + 1) if is_leaf: L[v] = 0 else: if ~p: R[v] = R[p] + 1 stack.append((~v, p)) for dst in E[v]: if dst == p: continue stack.append((dst, v)) for i in range(N): print(min(R[i], L[i]))