結果

問題 No.2532 Want Play More
ユーザー ntudantuda
提出日時 2023-12-23 13:29:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 157,836 KB
最終ジャッジ日時 2023-12-23 13:29:28
合計ジャッジ時間 8,995 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 452 ms
121,176 KB
testcase_04 AC 417 ms
120,392 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 AC 88 ms
76,924 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 233 ms
98,136 KB
testcase_11 AC 235 ms
97,736 KB
testcase_12 AC 370 ms
110,984 KB
testcase_13 AC 265 ms
101,844 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 35 ms
53,460 KB
testcase_21 AC 34 ms
53,460 KB
testcase_22 AC 35 ms
53,460 KB
testcase_23 AC 36 ms
53,460 KB
testcase_24 AC 36 ms
53,460 KB
testcase_25 AC 35 ms
53,460 KB
testcase_26 AC 34 ms
53,460 KB
testcase_27 AC 34 ms
53,460 KB
testcase_28 AC 326 ms
157,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N-1)]
E = [[] for _ in range(N)]
for a,b in AB:
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)

X = [0] * N
P = [-1] * N
def dfs(x,p):
    tmp = 1
    for y in E[x]:
        if y != p:
            P[y] = x
            tmp += dfs(y,x)
    X[x] = tmp
    return tmp

def search(a):
    q = [0]
    cnt = 0
    while q:
        q2 = []
        while q:
            tmp = []
            x = q.pop(-1)
            if (cnt+a) & 1:
                maxy = 0
                for y in E[x]:
                    if P[x] != y:
                        if X[y] > maxy:
                            tmp = [y]
                            maxy = X[y]
                        elif X[y] == maxy:
                            tmp.append(y)
                #print("a",tmp,maxy)
            else:
                minx = N
                for y in E[x]:
                    if P[x] != y:
                        if X[y] < minx:
                            tmp = [y]
                            minx = X[y]
                        elif X[y] == minx:
                            tmp.append(y)
                #print("b",tmp,minx)
            q2 += tmp
        cnt += 1
        q,q2 = q2,q
    return cnt

dfs(0,-1)
print(search(1)-1)
print(search(0)-1)


0