結果

問題 No.1424 Ultrapalindrome
ユーザー rlangevinrlangevin
提出日時 2023-03-01 23:13:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 86,296 KB
実行使用メモリ 107,720 KB
最終ジャッジ日時 2023-10-15 02:49:21
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,400 KB
testcase_01 AC 87 ms
71,424 KB
testcase_02 AC 89 ms
71,524 KB
testcase_03 WA -
testcase_04 AC 90 ms
71,348 KB
testcase_05 WA -
testcase_06 AC 90 ms
71,232 KB
testcase_07 AC 91 ms
71,276 KB
testcase_08 WA -
testcase_09 AC 210 ms
99,460 KB
testcase_10 AC 205 ms
99,716 KB
testcase_11 AC 171 ms
91,892 KB
testcase_12 AC 189 ms
98,248 KB
testcase_13 AC 131 ms
80,548 KB
testcase_14 AC 175 ms
95,592 KB
testcase_15 AC 92 ms
71,440 KB
testcase_16 AC 155 ms
90,576 KB
testcase_17 AC 172 ms
91,940 KB
testcase_18 AC 156 ms
87,232 KB
testcase_19 AC 181 ms
94,412 KB
testcase_20 AC 128 ms
81,388 KB
testcase_21 AC 156 ms
90,400 KB
testcase_22 AC 149 ms
84,740 KB
testcase_23 AC 111 ms
77,828 KB
testcase_24 AC 123 ms
78,872 KB
testcase_25 AC 122 ms
78,476 KB
testcase_26 AC 211 ms
96,884 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 178 ms
105,812 KB
testcase_31 AC 172 ms
105,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from collections import deque



N = int(readline())
G = [[] for i in range(N)]
D = [0] * N
for i in range(N - 1):
    A, B = map(int, readline().split())
    A, B = A - 1, B - 1
    G[A].append(B)
    G[B].append(A)
    D[A] += 1
    D[B] += 1
    
Q = deque()
dist = dict()
for i in range(N):
    dist[i] = -1
par = [-1] * N
for i in range(N):
    if D[i] == 1:
        Q.append(i)
        dist[i] = 0
        
while Q:
    u = Q.popleft()
    for v in G[u]:
        if v == par[u]:
            continue
        if dist[v] != -1:
            if -1 in dist:
                print("No")
                exit()
            if dist[v] == dist[u]:
                print("No")
                exit()
            continue
        dist[v] = dist[u] + 1
        par[v] = u
        Q.append(v)
print("Yes")
0