結果

問題 No.1424 Ultrapalindrome
ユーザー ygd.ygd.
提出日時 2021-03-12 21:49:41
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 870 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 91,648 KB
最終ジャッジ日時 2024-04-22 12:42:44
合計ジャッジ時間 6,048 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
51,584 KB
testcase_01 AC 42 ms
52,096 KB
testcase_02 AC 47 ms
52,224 KB
testcase_03 AC 43 ms
52,096 KB
testcase_04 AC 42 ms
52,096 KB
testcase_05 AC 43 ms
52,096 KB
testcase_06 AC 42 ms
51,968 KB
testcase_07 AC 43 ms
51,968 KB
testcase_08 AC 43 ms
51,584 KB
testcase_09 AC 180 ms
84,608 KB
testcase_10 AC 247 ms
86,144 KB
testcase_11 AC 192 ms
82,688 KB
testcase_12 AC 172 ms
84,480 KB
testcase_13 AC 103 ms
77,696 KB
testcase_14 AC 204 ms
83,712 KB
testcase_15 AC 45 ms
52,992 KB
testcase_16 AC 136 ms
81,280 KB
testcase_17 AC 146 ms
81,792 KB
testcase_18 AC 156 ms
80,896 KB
testcase_19 AC 204 ms
83,328 KB
testcase_20 AC 128 ms
78,080 KB
testcase_21 RE -
testcase_22 AC 163 ms
79,872 KB
testcase_23 AC 93 ms
77,184 KB
testcase_24 AC 127 ms
78,336 KB
testcase_25 AC 121 ms
78,464 KB
testcase_26 AC 221 ms
84,480 KB
testcase_27 AC 262 ms
89,344 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 176 ms
90,788 KB
testcase_31 AC 153 ms
88,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a-=1;b-=1 #0-index
    G[a].append(b); G[b].append(a)

L = []
def dfs1(v,par=-1): #jは次数
    L.append(v)
    for u in G[v]:
        if u == par: continue
        dfs1(u,v)
        break
        
for i in range(N):
    if len(G[i]) == 1:
        dfs1(i)
        break
#print(L)

if len(L) == N: print("Yes"); exit() #一直線

dic = {}
def dfs2(v,par,j):
    if j in dic:
        dic[j] += 1
    else:
        dic[j] = 1
    for u in G[v]:
        if u == par: continue
        dfs2(u,v,j+1)
    
if len(L)%2 != 0:
    NL = len(L)
    root = L[NL//2]
    dfs2(root,-1,0)
    idx = 1
    while idx in dic:
        if dic[idx] == dic[1]:
            idx += 1
            continue
        else:
            print("No");exit()
    print("Yes")
else:
    print("No")
0