結果

問題 No.1424 Ultrapalindrome
ユーザー rlangevinrlangevin
提出日時 2023-03-01 23:08:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 784 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 88,516 KB
最終ジャッジ日時 2023-10-15 02:46:11
合計ジャッジ時間 8,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
75,868 KB
testcase_01 AC 92 ms
71,788 KB
testcase_02 AC 92 ms
71,600 KB
testcase_03 WA -
testcase_04 AC 89 ms
71,688 KB
testcase_05 AC 87 ms
71,588 KB
testcase_06 AC 92 ms
71,796 KB
testcase_07 AC 89 ms
71,468 KB
testcase_08 AC 90 ms
71,780 KB
testcase_09 AC 174 ms
88,468 KB
testcase_10 AC 182 ms
88,516 KB
testcase_11 AC 153 ms
83,956 KB
testcase_12 AC 176 ms
88,440 KB
testcase_13 AC 121 ms
78,660 KB
testcase_14 AC 155 ms
84,492 KB
testcase_15 AC 89 ms
71,772 KB
testcase_16 AC 143 ms
83,524 KB
testcase_17 AC 149 ms
84,444 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = [-1] * N
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()
        dist[v] = dist[u] + 1
        par[v] = u
        Q.append(v)
print("Yes")
0