結果

問題 No.1424 Ultrapalindrome
ユーザー wolgnikwolgnik
提出日時 2021-03-12 22:17:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 99,764 KB
最終ジャッジ日時 2024-04-22 17:10:31
合計ジャッジ時間 4,164 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,224 KB
testcase_01 AC 36 ms
52,096 KB
testcase_02 AC 36 ms
51,840 KB
testcase_03 AC 35 ms
52,096 KB
testcase_04 AC 35 ms
52,224 KB
testcase_05 AC 36 ms
52,352 KB
testcase_06 AC 35 ms
52,608 KB
testcase_07 AC 34 ms
51,840 KB
testcase_08 AC 36 ms
52,224 KB
testcase_09 AC 106 ms
86,144 KB
testcase_10 AC 106 ms
85,888 KB
testcase_11 AC 89 ms
81,604 KB
testcase_12 AC 107 ms
86,144 KB
testcase_13 AC 59 ms
75,008 KB
testcase_14 AC 89 ms
82,176 KB
testcase_15 AC 37 ms
52,096 KB
testcase_16 AC 83 ms
81,152 KB
testcase_17 AC 88 ms
81,832 KB
testcase_18 AC 92 ms
80,896 KB
testcase_19 AC 116 ms
83,968 KB
testcase_20 AC 76 ms
77,824 KB
testcase_21 AC 107 ms
81,792 KB
testcase_22 AC 92 ms
80,128 KB
testcase_23 AC 56 ms
69,888 KB
testcase_24 AC 75 ms
77,824 KB
testcase_25 AC 68 ms
75,028 KB
testcase_26 AC 132 ms
85,376 KB
testcase_27 AC 128 ms
89,088 KB
testcase_28 AC 88 ms
85,504 KB
testcase_29 AC 99 ms
87,552 KB
testcase_30 AC 123 ms
99,764 KB
testcase_31 AC 122 ms
99,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
e = [[] for _ in range(N + 1)]
inc = [0] * (N + 1)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  inc[u] += 1
  inc[v] += 1

if max(inc) <= 2:
  print("Yes")
  exit(0)

root = 1
for x in range(1, N + 1):
  if inc[root] < inc[x]: root = x

s = [root]
vis = [0] * (N + 1)
vis[root] = 1
depth = [0] * (N + 1)
while len(s):
  x = s.pop()
  for y in e[x]:
    if vis[y]: continue
    vis[y] = 1
    s.append(y)
    if inc[y] > 2:
      print("No")
      exit(0)
    depth[y] = depth[x] + 1

leaves = []
for x in range(1, N + 1):
  if inc[x] == 1: leaves.append(depth[x])

if len(set(leaves)) == 1: print("Yes")
else: print("No")
0