結果

問題 No.1424 Ultrapalindrome
ユーザー ygd.ygd.
提出日時 2021-03-12 21:50:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 220,168 KB
最終ジャッジ日時 2023-08-04 18:59:10
合計ジャッジ時間 7,501 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,192 KB
testcase_01 AC 70 ms
71,192 KB
testcase_02 AC 69 ms
71,172 KB
testcase_03 AC 70 ms
71,172 KB
testcase_04 AC 71 ms
71,192 KB
testcase_05 AC 71 ms
71,332 KB
testcase_06 AC 71 ms
71,308 KB
testcase_07 AC 71 ms
71,324 KB
testcase_08 AC 71 ms
70,972 KB
testcase_09 AC 171 ms
85,756 KB
testcase_10 AC 226 ms
87,444 KB
testcase_11 AC 195 ms
84,776 KB
testcase_12 AC 182 ms
85,464 KB
testcase_13 AC 119 ms
78,784 KB
testcase_14 AC 216 ms
85,788 KB
testcase_15 AC 74 ms
71,340 KB
testcase_16 AC 143 ms
82,048 KB
testcase_17 AC 150 ms
82,808 KB
testcase_18 AC 160 ms
82,144 KB
testcase_19 AC 220 ms
84,996 KB
testcase_20 AC 144 ms
80,496 KB
testcase_21 AC 284 ms
140,436 KB
testcase_22 AC 170 ms
83,448 KB
testcase_23 AC 105 ms
78,068 KB
testcase_24 AC 153 ms
93,268 KB
testcase_25 AC 142 ms
86,200 KB
testcase_26 AC 213 ms
87,100 KB
testcase_27 AC 251 ms
90,436 KB
testcase_28 AC 315 ms
187,068 KB
testcase_29 AC 559 ms
220,168 KB
testcase_30 AC 190 ms
92,124 KB
testcase_31 AC 164 ms
92,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(500000)
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