結果

問題 No.1424 Ultrapalindrome
ユーザー nephrologistnephrologist
提出日時 2021-03-12 21:49:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 97,920 KB
最終ジャッジ日時 2024-04-22 12:42:12
合計ジャッジ時間 4,895 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,760 KB
testcase_01 AC 42 ms
54,016 KB
testcase_02 AC 42 ms
54,144 KB
testcase_03 AC 42 ms
54,144 KB
testcase_04 AC 43 ms
54,144 KB
testcase_05 WA -
testcase_06 AC 44 ms
53,376 KB
testcase_07 AC 43 ms
54,144 KB
testcase_08 WA -
testcase_09 AC 140 ms
84,480 KB
testcase_10 AC 140 ms
84,736 KB
testcase_11 AC 123 ms
82,944 KB
testcase_12 AC 138 ms
84,480 KB
testcase_13 AC 89 ms
79,360 KB
testcase_14 AC 124 ms
83,584 KB
testcase_15 AC 44 ms
54,400 KB
testcase_16 AC 115 ms
82,304 KB
testcase_17 AC 120 ms
83,328 KB
testcase_18 AC 121 ms
81,920 KB
testcase_19 AC 150 ms
83,584 KB
testcase_20 AC 90 ms
78,208 KB
testcase_21 AC 130 ms
82,432 KB
testcase_22 AC 114 ms
80,640 KB
testcase_23 AC 62 ms
68,608 KB
testcase_24 AC 78 ms
73,984 KB
testcase_25 AC 76 ms
73,472 KB
testcase_26 AC 161 ms
84,352 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 118 ms
97,920 KB
testcase_31 AC 121 ms
97,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

input = sys.stdin.buffer.readline

n = int(input())
graph = [[] for _ in range(n)]
deg1 = [0] * n
deg2 = [0] * n
for _ in range(n - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)
    deg1[a] += 1
    deg1[b] += 1
root = -1
kouho = deque()
dist = [-1] * n
done = [0] * n
for i in range(n):
    if deg1[i] != 1:
        root = i
    if deg1[i] == 1:
        kouho.append(i)
        dist[i] = 0
        done[i] = 1


def ok():
    print("Yes")
    exit()


def ng():
    print("No")
    exit()


if root == -1:
    if n == 2:
        ok()
    else:
        ng()


# bfs
# print("kouho", kouho)

while kouho:
    v = kouho.popleft()
    d = dist[v]
    for u in graph[v]:
        done[u] = 1
        if dist[u] == -1:
            dist[u] = d + 1
            kouho.append(u)
        else:
            if dist[u] != d + 1 and dist[u] != d - 1:
                # print("ng", v, u)
                ng()

ok()
0