結果

問題 No.1424 Ultrapalindrome
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-12 22:42:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,102 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 109,240 KB
最終ジャッジ日時 2024-04-22 14:01:29
合計ジャッジ時間 7,549 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,888 KB
testcase_01 AC 43 ms
53,632 KB
testcase_02 AC 43 ms
53,760 KB
testcase_03 AC 40 ms
52,352 KB
testcase_04 AC 43 ms
53,888 KB
testcase_05 WA -
testcase_06 AC 43 ms
54,016 KB
testcase_07 AC 43 ms
53,632 KB
testcase_08 WA -
testcase_09 AC 233 ms
98,264 KB
testcase_10 AC 244 ms
98,164 KB
testcase_11 AC 156 ms
90,536 KB
testcase_12 AC 189 ms
96,060 KB
testcase_13 AC 115 ms
81,792 KB
testcase_14 AC 203 ms
92,704 KB
testcase_15 AC 45 ms
54,400 KB
testcase_16 AC 141 ms
85,052 KB
testcase_17 AC 163 ms
91,220 KB
testcase_18 AC 190 ms
83,644 KB
testcase_19 AC 194 ms
90,568 KB
testcase_20 AC 112 ms
80,128 KB
testcase_21 AC 144 ms
85,196 KB
testcase_22 AC 126 ms
83,584 KB
testcase_23 AC 87 ms
72,576 KB
testcase_24 AC 97 ms
79,488 KB
testcase_25 AC 100 ms
79,104 KB
testcase_26 AC 199 ms
92,984 KB
testcase_27 WA -
testcase_28 AC 116 ms
97,412 KB
testcase_29 WA -
testcase_30 AC 919 ms
107,688 KB
testcase_31 AC 909 ms
109,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n = int(input())
g = [[] for i in range(n)]
G = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    G[a].append(b)
    G[b].append(a)
    g[a].append(b)
    g[b].append(a)

if n == 2:
    print('Yes')
    exit()

from collections import deque
q = deque([])
leaf = []
for v in range(n):
    if len(g[v]) == 1:
        q.append(v)
        leaf.append(v)

if len(q) == 2:
    print('Yes')
    exit()

N = n
while N > 2:
    l = len(q)
    N -= l
    for i in range(l):
        v = q.popleft()
        for u in g[v]:
            g[u].remove(v)
            if len(g[u]) == 1:
                q.append(u)
#print(list(q))
if len(q) >= 2:
    print('No')
    exit()
s = q[0]
#print(s)
q = deque([])
q.append(s)
dist = [-1]*len(g)
dist[s] = 0
while q:
    v = q.popleft()
    for u in G[v]:
        if dist[u] == -1:
            dist[u] = dist[v]+1
            q.append(u)
D = set()
for l in leaf:
    D.add(dist[l])
if len(D) == 1:
    print('Yes')
else:
    print('No')
0