結果

問題 No.2638 Initial fare
ユーザー こめだわらこめだわら
提出日時 2024-02-19 21:36:16
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 576 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 583,136 KB
最終ジャッジ日時 2024-02-19 21:36:32
合計ジャッジ時間 14,555 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 31 ms
53,460 KB
testcase_02 AC 29 ms
53,460 KB
testcase_03 AC 31 ms
53,460 KB
testcase_04 AC 408 ms
100,608 KB
testcase_05 AC 425 ms
101,572 KB
testcase_06 AC 32 ms
53,460 KB
testcase_07 AC 366 ms
102,832 KB
testcase_08 AC 288 ms
103,760 KB
testcase_09 AC 308 ms
105,988 KB
testcase_10 AC 285 ms
105,880 KB
testcase_11 AC 32 ms
53,460 KB
testcase_12 AC 391 ms
102,684 KB
testcase_13 AC 275 ms
102,792 KB
testcase_14 AC 344 ms
106,548 KB
testcase_15 AC 298 ms
106,432 KB
testcase_16 AC 32 ms
53,460 KB
testcase_17 AC 391 ms
105,092 KB
testcase_18 AC 282 ms
104,948 KB
testcase_19 AC 688 ms
197,496 KB
testcase_20 AC 426 ms
115,976 KB
testcase_21 AC 1,277 ms
176,364 KB
testcase_22 AC 35 ms
53,460 KB
testcase_23 AC 1,209 ms
376,212 KB
testcase_24 AC 1,378 ms
385,024 KB
testcase_25 AC 32 ms
53,460 KB
testcase_26 AC 1,233 ms
233,592 KB
testcase_27 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(500000)

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

used=[0]*N
total=0
def dfs(i):
    global total
    used[i]=1
    dp=[0,0,0]
    c=[0,0,0]
    for np in edge[i]:
        if used[np]==1:
            continue
        d=dfs(np)
        total+=d[0]*c[0]+d[0]*c[1]+d[1]*c[0]
        for j in range(3):
            c[j]+=d[j]
    total+=c[0]+c[1]+c[2]
    dp[0]=1
    dp[1]=c[0]
    dp[2]=c[1]
    return dp

dfs(0)
print(total)
0