結果

問題 No.1424 Ultrapalindrome
ユーザー 小野寺健小野寺健
提出日時 2021-05-20 14:45:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 905 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-04-18 14:03:18
合計ジャッジ時間 10,637 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
17,820 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 33 ms
10,752 KB
testcase_03 AC 32 ms
10,752 KB
testcase_04 AC 32 ms
10,752 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 33 ms
10,752 KB
testcase_07 AC 32 ms
10,752 KB
testcase_08 AC 34 ms
10,880 KB
testcase_09 AC 1,031 ms
34,688 KB
testcase_10 AC 1,036 ms
34,816 KB
testcase_11 AC 767 ms
27,776 KB
testcase_12 AC 973 ms
33,280 KB
testcase_13 AC 269 ms
17,152 KB
testcase_14 AC 791 ms
29,312 KB
testcase_15 AC 31 ms
10,752 KB
testcase_16 AC 625 ms
25,472 KB
testcase_17 AC 769 ms
28,544 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 #

N = int(input())

P = [0] * N
Edge = []

for _ in range(N-1):
    v, u = map(int, input().split())
    P[v-1] += 1
    P[u-1] += 1
    Edge.append((v-1, u-1))
    Edge.append((u-1, v-1))
    
S = [k for k, v in enumerate(P) if v == 1]

def getPath(s, i):
    global N, P, S
    D = [float('inf')] * N
    D[s] = 0
    while True:
        update = False
        for f, t in Edge:
            if D[f] != float('inf') and D[t] > D[f] + 1:
                D[t] = D[f] + 1
                update = True
        if not update:
            break
    
    res = -1
    for e in S[i+1:]:
        if res < 0:
            res = D[e]
        elif res != D[e]:
            return -1
    return res

res = -1
for i, s in enumerate(S[:-1]):
    v = getPath(s, i)
    if v < 0:
        print('No')
        break
    elif res < 0:
        res = v
    elif res != v:
        print('No')
        break
else:
    print('Yes')
0