結果

問題 No.1424 Ultrapalindrome
ユーザー あかりきあかりき
提出日時 2021-03-12 21:42:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 82,788 KB
実行使用メモリ 132,308 KB
最終ジャッジ日時 2024-04-22 12:32:39
合計ジャッジ時間 6,845 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,768 KB
testcase_01 AC 43 ms
54,172 KB
testcase_02 AC 38 ms
52,684 KB
testcase_03 AC 38 ms
52,720 KB
testcase_04 AC 38 ms
52,216 KB
testcase_05 AC 38 ms
53,192 KB
testcase_06 AC 38 ms
53,240 KB
testcase_07 AC 39 ms
54,240 KB
testcase_08 WA -
testcase_09 AC 287 ms
100,384 KB
testcase_10 AC 294 ms
100,876 KB
testcase_11 AC 224 ms
92,136 KB
testcase_12 AC 269 ms
98,296 KB
testcase_13 AC 143 ms
82,296 KB
testcase_14 AC 234 ms
93,952 KB
testcase_15 AC 41 ms
53,816 KB
testcase_16 AC 205 ms
90,544 KB
testcase_17 AC 223 ms
93,320 KB
testcase_18 AC 185 ms
90,540 KB
testcase_19 AC 230 ms
91,120 KB
testcase_20 AC 121 ms
80,100 KB
testcase_21 AC 197 ms
88,104 KB
testcase_22 AC 157 ms
84,344 KB
testcase_23 AC 94 ms
77,412 KB
testcase_24 AC 125 ms
80,104 KB
testcase_25 AC 127 ms
79,892 KB
testcase_26 AC 259 ms
93,880 KB
testcase_27 WA -
testcase_28 AC 215 ms
101,380 KB
testcase_29 AC 217 ms
101,564 KB
testcase_30 AC 243 ms
132,308 KB
testcase_31 AC 252 ms
132,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

L=[]
for i in range(n):
  if len(connection[i])==1:
    L.append(i)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

B=bfs(L[0])
B2=bfs(L[1])
ans=[]
for i in range(1,len(L)):
  x=L[i]
  ans.append(B[x])
ans2=[]
for i in range(len(L)):
  if i!=1:
    x=L[i]
    ans2.append(B2[x])

if len(set(ans))==1 and len(set(ans2))==1:
  print('Yes')
else:
  print('No')
0